Image refinement is an important technology in pattern recognition, it refers to simplifying the original "bloated" pixels into a single-pixel binary image (similar to the skeleton concept). The quality of refinement directly affects the efficiency of subsequent identification and matching.
From an article, the refinement is to remove some points from the original graph layer by layer, but keep the original shape until the skeleton of the image is obtained. The skeleton can be understood as the central axis of an image. For example, a rectangular skeleton is its long side up the central axis; a square skeleton is its center point; a circle skeleton is its center, the skeleton of a straight line is itself, and the skeleton of an isolated point is itself.
Next we will first introduce the classic parallel rapid refinement algorithm of Zhang:
Set the eight neighborhoods of Point P1:
[P9 P2 p3
P8 P1 p4
P7 P6 P5]
(P1 is a white point. If the following four conditions are met, delete P1, that is, P1 = 0)
Iterations are divided into two subprocesses:
In process 1, the deletion conditions are as follows: (1), 2 <= N (P1) <= 6, and n (x) is the number of black spots in the 8-neighborhood of X.
(2), A (p1) = 1, A (x) refers to the p2-p8 in order before and after respectively 0, 1 logarithm (background color: 0)
(3) p2 * p4 * p6 = 0
(4) p4 * p6 * p8 = 0
If both the preceding four conditions are met, the point can be deleted (with a value of 0 ).
Process 2 refined deletion conditions: (1), 2 <= N (p1) <= 6, N (x) is the number of black spots in the 8-neighborhood of x
(2), A (p1) = 1, A (x) refers to the p2-p8 in order before and after respectively 0, 1 logarithm (background color: 0)
(3) p2 * p4 * p8 = 0
(4) p2 * p6 * p8 = 0
If the above four conditions are met, the point can be deleted.
The Code is as follows:
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
Main function code:
1 test = input ('Please input a digits image: ','s'); % input image
2 x = imread (test );
3 if ~ Isbw (x)
4' make sure that the input image is a binarization image! ';
5 else
6 [height, width] = size (x );
7 mark = 1;
8% temp = zeros (height + 2, width + 2 );
9% temp (2: height +: 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% determine whether P (r, c) is a refined Pixel
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% determine whether P (r, c) is a refined Pixel
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
Result: