现在的位置: 首页 > 综合 > 正文

图像细化(骨架化)算法 分析

2013年02月20日 ⁄ 综合 ⁄ 共 2376字 ⁄ 字号 评论关闭

图像的细化是模式识别中很重要的一个技术,指的是将原本"臃肿"的像素简化为单像素相连接的二值图像(即类似骨架的概念),细化的好坏直接影响到后面识别匹配的效率。

摘自某文章的话,细化就是经过一层层的剥离,从原来的图中去掉一些点,但仍要保持原来的形状,直到得到图像的骨架。骨架,可以理解为图象的中轴,例如一个长方形的骨架是它的长方向上的中轴线;正方形的骨架是它的中心点;圆的骨架是它的圆心,直线的骨架是它自身,孤立点的骨架也是自身。

 

下面先介绍经典的Zhang并行快速细化算法

设p1点的八邻域为:

      【    p9    p2     p3

             p8    p1     p4

                  p7    p6     p5 】

(其中p1为白点,如果以下四个条件同时满足,则删除p1,即令p1=0)

其中迭代分为两个子过程:

     过程1 细化删除条件为:        (1)、2 < =N(p1) <= 6,   N(x)为x的8邻域中黑点的数目

                                           (2)、A(p1)=1,    A(x)指的是将p2-p8之间按序前后分别为0、1的对数(背景色:0

                                           (3)、p2*p4*p6=0            

                                           (4)、p4*p6*p8=0

           如果同时满足以上四个条件则该点可以删除(赋值为0)。

    过程2 细化删除条件为:        (1)、2 < =N(p1) <= 6,   N(x)为x的8邻域中黑点的数目

                                           (2)、A(p1)=1,    A(x)指的是将p2-p8之间按序前后分别为0、1的对数(背景色:0

                                           (3)、p2*p4*p8=0            

                                           (4)、p2*p6*p8=0

           如果同时满足以上四个条件则该点可以删除。

代码如下:

A.m

1 function n=A(temp,i,j)
2 %0->1的数目
3 shuzu=[temp(i,j),temp(i-1,j),temp(i-1,j+1),temp(i,j+1),temp(i+1,j+1),temp(i+1,j),temp(i+1,j-1),temp(i,j-1),temp(i-1,j-1)];
4 n=0;
5 for i=2:8
6 if shuzu(i)==0&&shuzu(i+1)==1
7 n=n+1;
8 end
9 end

主函数代码:

 1 test=input('Please input a digits image:','s'); %输入图像
2 x=imread(test);
3 if ~isbw(x)
4 '请确保输入图像为二值化图像!';
5 else
6 [height,width]=size(x);
7 mark=1;
8 % temp=zeros(height+2,width+2);
9 % temp(2:height+1,2:width+1)=x(:,:);
10 temp=x;
11 imshow(temp);
12 while mark==1
13 mark=0;
14
15 for i=2:height-1
16 for j=2:width-1
17 condition=0;
18 %判断P(r,c)是否为可细化像素
19 if temp(i,j)==1
20 n=0;
21 for ii=-1:1
22 for jj=-1:1
23 n=n+temp(i+ii,j+jj);
24 end
25 end
26 if (n>=3 && n<=7)
27 condition=condition+1;
28 end
29 if A(temp,i,j)==1
30 condition=condition+1;
31 end
32 if temp(i-1,j)*temp(i,j+1)*temp(i+1,j)==0
33 condition=condition+1;
34 end
35 if temp(i,j+1)*temp(i+1,j)*temp(i,j-1)==0
36 condition=condition+1;
37 end
38 if condition==4
39 mark=1;
40 temp(i,j)=0;
41 end
42 end
43 end
44 end
45 figure;imshow(temp);
46
47
48 for i=2:height-1
49 for j=2:width-1
50 condition=0;
51 %判断P(r,c)是否为可细化像素
52 if temp(i,j)==1
53 n=0;
54 for ii=-1:1
55 for jj=-1:1
56 n=n+temp(i+ii,j+jj);
57 end
58 end
59 if (n>=3 && n<=7)
60 condition=condition+1;
61 end
62 if A(temp,i,j)==1
63 condition=condition+1;
64 end
65 if temp(i-1,j)*temp(i,j+1)*temp(i,j-1)==0
66 condition=condition+1;
67 end
68 if temp(i,j-1)*temp(i+1,j)*temp(i,j-1)==0
69 condition=condition+1;
70 end
71 if condition==4
72 mark=1;
73 temp(i,j)=0;
74 end
75 end
76 end
77 end
78 figure;imshow(temp);
79 end
80 end

结果:

 

抱歉!评论已关闭.