加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Hilditch 细化算法 (matlab版本)

(2013-03-22 11:01:04)
分类: 数理逻辑类

原理见我的博文中的c版本:

clc
clear all
A=imread('D:\test.bmp');
figure(1)
imshow(A)
[w,l]=size(A);
B=zeros(w,l);
%%%%%%%%%对图形进行预处理包括255处理为1,还有加上全1的边框
for i=1:w
    for j=1:l
        if(A(i,j)==255)
            B(i,j)=1;
        else
            B(i,j)=0;
        end
    end
end
mark=zeros(w,l);
temp=0;
for i=2:w-1
    for j=2:l-1
        %%step1: weather p is 0,that is ,p is not background
        if(B(i,j)~=0)
            continue;
        end
        B(i,j)
        B(i,j+1)
        B(i+1,j+1)
        B(i-1,j)
        B(i-1,j-1)
        B(i-1,j)
        B(i+1,j-1)
        B(i+1,j)
        B(i+1,j+1)
        %%step2:X1,X3,X5,X7 can't be all 0
        if(B(i,j+1)==0&B(i-1,j)==0&B(i,j-1)==0&B(i+1,j)==0)
            continue;
        end
        %%step3:X1 to X8 ,at least two 0
        count=0;
        count=count+B(i,j+1)+B(i-1,j+1)+B(i-1,j)+B(i-1,j-1)+B(i,j-1)+B(i+1,j-1)+B(i+1,j)+B(i+1,j+1);
        if count>6
            continue;
        end
        %%step4:the connect's number of p is 1
        result=liantong(B(i,j+1),B(i-1,j+1),B(i-1,j),B(i-1,j-1),B(i,j-1),B(i+1,j-1),B(i+1,j),B(i+1,j+1));
        if result~=1
            continue;
        end
        %%step5:if the mark of X3 is delete,then x3 be 1,the connect's
        if mark(i-1,j)==1
            B(i-1,j)=1;
            result=liantong(B(i,j+1),B(i-1,j+1),B(i-1,j),B(i-1,j-1),B(i,j-1),B(i+1,j-1),B(i+1,j),B(i+1,j+1));
            if result~=1
                continue;
            end
            B(i-1,j)=0;
        end
        %%step6:if the mark of X5 is delete,then X5 be 1
        if(mark(i-1,j-1)==1)
            B(i-1,j-1)=1;
            result=liantong(B(i,j+1),B(i-1,j+1),B(i-1,j),B(i-1,j-1),B(i,j-1),B(i+1,j-1),B(i+1,j),B(i+1,j+1));
            if result~=1
                continue;
            end
            B(i-1,j-1)=0;
        end
        mark(i,j)=1;
    end
end
for i=1:w
    for j=1:l
        if(mark(i,j)==1)
            B(i,j)=1;
        end
    end
end
figure(2)
imshow(B)           

 

 

 

 

 

补充:liantong函数

function result=liantong(X1,X2,X3,X4,X5,X6,X7,X8)
count=0;
count=count+X1-X1*X2*X3;
count=count+X3-X3*X4*X5;
count=count+X5-X5*X6*X7;
count=count+X7-X7*X8*X1;
result=count;
end

           

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有