1 EE 355 OCR Explanation Mark Redekopp
2 Make Your Own Image • Note: You can make your own images by: – Using the "Verdana" font and writing some text in a word processor – Using the Windows "snipping" tool to capture a section of the screen – Paste it into an image editor (Windows Paint) – Resize the image to 256x256 – Save it as 8-bit Grayscale
3 Note about BFS 2 Now start a BFS using 8 Scan top to bottom, left to right 1 connected Stop when you hit a black, unfound pixel neighbors (N, NW, W, SW, S, SE, E, NE)
4 Note about BFS Row r Row r+1 Note: Due to slight image rendering discrepancies, characters further right might be found first since one of their pixels is in a higher row. In this image, 2 and 3 might be found before 1
5 Note about BFS 2 Now start a BFS using 8 Scan top to bottom, left to right 1 connected Stop when you hit a black, unfound pixel neighbors (N, NW, W, SW, S, SE, E, NE)
6 Euler Number • Euler number = # of components - # of holes • Component is connected black region – Each character is just 1 component • Holes are enclosed white regions – '8' has 2 holes, '0' has 1, '2' has none • Thus, Euler number, E = C-H = 1-H – E=1 => {1, 2, 3, 5, 7} – E=0 => {0, 4, 6, 9} – E=-1 => {8}
7 Center of Mass (Centroids) • Imagine black pixels represents mass in the image below • Where would the center of mass be? – Somewhere in the upper right • This can be useful for identifying certain characters ('7' = more mass in the upper half, '3' = more mass in the right half, etc.) Vertical center of mass is on row 1.1
8 Vertical Centroid • Equation – isblack(i,j) = 1 if pixel (i,j) is black, 0 otherwise 𝐼,𝑋 𝐼,𝑋 𝑗 ∗ 𝑗𝑡𝑐𝑚𝑏𝑑𝑙(𝑗, 𝑘) [ 𝑗𝑡𝑐𝑚𝑏𝑑𝑙(𝑗, 𝑘)] 𝑗,𝑘=0,0 𝑗,𝑘=0,0 – Multiple row index * 1 if the pixel is black and sum over all pixels – 0*1 + 0*1 + 0*1 + 0*1 + 0*1 + 0 1 2 3 4 0 Vertical center 1 1*1 + 2*1 + 3*1 + 4*1 = 10 of mass is on 2 row 1.1 3 – Total black pixels = 9 4 – Vertical centroid = 10/9 = 1.11
9 Horizontal Centroid • Equation – isblack(i,j) = 1 if pixel (i,j) is black, 0 otherwise 𝐼,𝑋 𝐼,𝑋 𝑘 ∗ 𝑗𝑡𝑐𝑚𝑏𝑑𝑙(𝑗, 𝑘) [ 𝑗𝑡𝑐𝑚𝑏𝑑𝑙(𝑗, 𝑘)] 𝑗,𝑘=0,0 𝑗,𝑘=0,0 – Multiple column index * 1 if the pixel is black and sum over all pixels – 0*1 + 1*1 + 2*1 + 3*1 + 4*1 + 0 1 2 3 4 0 1 4*1 + 4*1 + 4*1 + 4*1 = 26 2 3 – Total black pixels = 9 4 Horizontal center – Vertical centroid = 26/9 = 2.89 of mass is on column 2.89
10 Center of Mass (Centroids) • Putting the VC (Vertical centroid) and HC (Horizontal centroid) together we arrive at a center of mass of (1.1, 2.89) • It may be more useful to translate the coordinate system to have 0,0 be right in the middle which can easily be accomplished by: – (VC – H/2 , HC – W/2 ) => (1.1-2, 2.89-2) = (-0.9, 0.89) – This tells us the center of mass is in the upper (negative), left (positive) quadrant of the image -2 -1 0 1 2 Center of Center of Mass Mass -2 -1 0 1 2
11 Symmetry • Another useful characteristic might be vertical and horizontal symmetry – Mirror images top to bottom (vertical symmetry) or left to right (horizontal symmetry) 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 Vertical Horizontal Both Vertical & Symmetry Symmetry Horizontal Symmetry
12 Computing Vertical Symmetry • Scan down the top row and compare pixel values to the bottom row, then compare second row to second to last row, etc. – Count how many pixels you compared and how many matched – Likely helpful to normalize to a percentage 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 M1 M2 M3 M4 M5 0 0 1 M6 M7 M8 M9 MA 1 1 2 2 2 3 M6 M7 M8 M9 MA 3 3 4 M1 M2 M3 M4 M5 4 4 Vertical Horizontal Both Vertical & Symmetry Symmetry Horizontal Symmetry
13 Computing Bit Quads • To compute bit quads remember to start at one row and column above and to the left and continue to one row and column below and to the right (i.e. leave a frame of one row/column of white around the black pattern) 0 1 2 3 4 0 1 2 3 4 0 0 1 1 2 2 3 3 4 4 Vertical Horizontal Both Vertical & Symmetry Symmetry Horizontal Symmetry
14
Recommend
More recommend