1. Question:
Split the image and extract the zip code on the envelope.
2. algorithm principle:
Original: Liang Yijun (Xi'an Jiaotong University image Institute, [email protected])
(1) wire box extraction:
Input f (x, y) is a color image, and output g (x, y) is a gray image.
G (x, y) = T [F (x, y). r, f (x, y). B, F (x, y). R] t is a transform function.
T (R, G, B) = max {r-(G + B)/2, 0 };
After T function transformation, the red box is extracted, the value is 255, and the gray value of the remaining colors is 0.
(2) Extraction of character frame position: Projection Algorithm
Projection to the X axis map_x (x) =;
Projection to Y axis map_y (y) =;
After obtaining the position of the character box, you can use the corresponding algorithm to extract each zip code number.
We can continue to segment and refine zip code characters and extract features for final recognition. This is not discussed here.
3. Code:
Void main ()
{
Argb [,] f = loadcolorimg ();
If (F = NULL) return;
Showimg ("F", F );
Int W = f. getlength (0 );
Int H = f. getlength (1 );
Byte [,] G = new byte [W, H];
// Extract wireframes
For (INT x = 0; x <W; X ++)
For (INT y = 0; y
{
Double temp = f [x, y]. R-(F [x, y]. G + F [x, y]. B)/2.0;
If (temp> 0) g [x, y] = (byte) temp;
Else G [x, y] = 0;
}
// Display the extracted wiremap Image
Showimg ("g", G );
Int [] map_x = new int [w]; // projected value along the X axis
Int [] map_y = new int [H]; // The projection value along the Y axis.
For (INT x = 0; x <W; X ++)
Map_x [x] = 0;
For (INT y = 0; y
Map_y [y] = 0;
// Projection along the X axis
For (INT x = 0; x <W; X ++)
For (INT y = 0; y
Map_x [x] + = G [x, y];
// Projection along the Y axis
For (INT y = 0; y
For (INT x = 0; x <W; X ++)
Map_y [y] + = G [x, y];
Int [] pos_x = new int [6]; // The value of the x-axis box.
Int [] pos_y = new int [5]; // The value of the Y-axis box.
// Obtain the x-axis box mark Value
Int I = 0;
For (INT x = 0; x <W; X ++)
If (map_x [x] & gt; 510)
{
Pos_x [I ++] = X;
}
// Obtain the line box mark value of the Y axis
I = 0;
For (INT y = 0; y
If (map_y [y] & gt; 1540)
{
Pos_y [I ++] = y;
}
// Argb [,] g_new = new argb [W, H]; // display the segmented image in color.
Byte [,] g_new = new byte [W, H];
For (INT x = 0; x <W; X ++)
For (INT y = 0; y
// If (x> pos_x [4] & xpos_y [1] & Y
If (X! = Pos_x [0] & X! = Pos_x [1] & X! = Pos_x [2] & X! = Pos_x [3] & X! = Pos_x [4] & X! = Pos_x [5])
& (Y> pos_y [1] & Y <pos_y [2]) // obtain all zip code numbers, expressed in grayscale
G_new [x, y] = (bytes) (255-(f [x, y]. R + F [x, y]. G + F [x, y]. b)/3.0 ));
Showimg ("g_new", g_new );
}
4. Results
Figure 1 envelope source image F
Figure 2 extracted line diagram g
Figure 3 Split zip code g_new
Image processing-image cutting-extract the zip code on the envelope