圖像的細(xì)化是模式識(shí)別中很重要的一個(gè)技術(shù),指的是將原本"臃腫"的像素簡(jiǎn)化為單像素相連接的二值圖像(即類似骨架的概念),細(xì)化的好壞直接影響到后面識(shí)別匹配的效率。
摘自某文章的話,細(xì)化就是經(jīng)過(guò)一層層的剝離,從原來(lái)的圖中去掉一些點(diǎn),但仍要保持原來(lái)的形狀,直到得到圖像的骨架。骨架,可以理解為圖象的中軸,例如一個(gè)長(zhǎng)方形的骨架是它的長(zhǎng)方向上的中軸線;正方形的骨架是它的中心點(diǎn);圓的骨架是它的圓心,直線的骨架是它自身,孤立點(diǎn)的骨架也是自身。
下面先介紹經(jīng)典的Zhang并行快速細(xì)化算法:
設(shè)p1點(diǎn)的八鄰域?yàn)椋?/p>
【 p9 p2 p3
p8 p1 p4
p7 p6 p5 】
(其中p1為白點(diǎn),如果以下四個(gè)條件同時(shí)滿足,則刪除p1,即令p1=0)
其中迭代分為兩個(gè)子過(guò)程:
過(guò)程1 細(xì)化刪除條件為: (1)、2 < =N(p1) <= 6, N(x)為x的8鄰域中黑點(diǎn)的數(shù)目
(2)、A(p1)=1,
A(x)指的是將p2-p8之間按序前后分別為0、1的對(duì)數(shù)(背景色:0)
(3)、p2*p4*p6=0
(4)、p4*p6*p8=0
如果同時(shí)滿足以上四個(gè)條件則該點(diǎn)可以刪除(賦值為0)。
過(guò)程2 細(xì)化刪除條件為: (1)、2 < =N(p1) <= 6, N(x)為x的8鄰域中黑點(diǎn)的數(shù)目
(2)、A(p1)=1,
A(x)指的是將p2-p8之間按序前后分別為0、1的對(duì)數(shù)(背景色:0)
(3)、p2*p4*p8=0
(4)、p2*p6*p8=0
如果同時(shí)滿足以上四個(gè)條件則該點(diǎn)可以刪除。
代碼如下:
A.m
1 function n=A(temp,i,j)
2 %0->1的數(shù)目
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
主函數(shù)代碼:

1 test=input('Please input a digits image:','s'); %輸入圖像
2 x=imread(test);
3 if ~isbw(x)
4 '請(qǐng)確保輸入圖像為二值化圖像!';
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)是否為可細(xì)化像素
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)是否為可細(xì)化像素
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

結(jié)果:
