300 likes | 449 Views
Fast and Accurate Skew Estimation Based on Distance Transform. An article by: Itay Bar-Yosef, Nate Hagbi, Klara Kedem , Itshak Dinstein Computer Science Department Ben-Gurion University Beer-Sheva, Israel Presented by: Doron Ben-Zion and Michael Wasserstrum. Distance Transform.
E N D
Fast and Accurate Skew Estimation Based on Distance Transform An article by: Itay Bar-Yosef, Nate Hagbi, KlaraKedem, ItshakDinstein Computer Science Department Ben-Gurion University Beer-Sheva, Israel Presented by: Doron Ben-Zion and Michael Wasserstrum
Distance Transform • A distance transform, also known as distance map or distance field, is a derived representation of a digital image. • Derived – extracting information from the original image. • We label each pixel of the image with the Euclidian Distance to the nearest ”obstacle pixel”, which in our case is the foreground pixel. • For each pixel x : • DT(x) = distance (x,y) where y stands for the nearest pixel in the foreground.
The distance transform is sometimes very sensitive to small changes in the object. If, for example, we take this rectangle which contains a small black region in the center of the white rectangle, then the Distance Transform becomes:
An example of applying the Distance Transform to a real world image is illustrated with: • To obtain a binary input image, we threshold the image at a value of 100, as shown in: • The Distance Transform is:
Linear Algorithm of Distance Tranform • To preform an estimation of DT on a given binary matrix (which represents an image) we will use one kind of the 3 given “masks” – where each one of them represent a different metric. L1 – Matrix (Diamond) L2 – Matrix (euclidean) L∞ - Matrix -1 0 1 -1 0 1 Computers “prefer” working with integers so to simplify the process we multiply the numbers by 100 while preserving the ratios
Algorithm • For a Given image matrix A (m*n) and a given mask M: • Initialize every background pixel to ∞ and every foreground pixel to zero. • For k = 1 until m (Top down) • For s = 1 until n (Left to right) • A[k,s] = min{A[k+i,s+j] + M[i,j]} -1 ≤ i ≤ 1 -1 ≤ j ≤ 1 • For k = m down to 1 (Botton up) • For s = n down to 1 (Right to left) • A[k,s] = min{A[k+i,s+j] + M[i,j]} -1 ≤ i ≤ 1 -1 ≤ j ≤ 1 • In our case we will use L2 (euclidiean mask). Loop 1 Loop 2
Explanation • Note that we do change ‘A’ and don’t create a new Matrix (image). • Means that if we have changed a value of a pixel, its new value will be taken in consideration in the upcoming iterations. • Also note that in the first loop we do not consider values to the right of the pixel that can be later changed! • That is why we need the second loop!
Distance Transform – even faster! • We can use only part of the mask in each loop! Distance Transform – more accurate! • If we would like to increase the accuracy of the Distance Transform we can use a larger mask. • We’ll pay more in running time. • mask gives “Good Enough” results.
Skew Estimantion: • Document skew estimation is an important step in the process of document analysis. • It affect the performance of subsequent stages of document capturing process such as: • line extraction. • page segmentation. • OCR - Optical character recognition. • We will use Distance Transform to estimate the skew of a document.
Process Steps • Use Thresholding to obtain a Binarized Document. • Use Distance Transform. • Use Gaussian Blur for smoothing the Image. • Calculate the gradient for each backround pixel. • Calculate the average orientation for a specific window. • Produce an histogram. • Calculate a gaussien on top of the histogram. • Return The Gaussien central value!
1. Thresholding Binarized Documents • Binarized Document is a document represented only by 2 values of pixels: 0 & 1. usually we use 0 for black and 1 for white. • To obtain a Binarized Document from a gray scale document we simply use a Threshold. • In our case “Otsu’s global thresholding approach” was used.
Example of Otsu’s Thresholding Binarized Image Original Image
Why using Thresholding? • We don’t need color information for estimating the document orientation. • It’s crucial for Distance Transform - an important step in our skew estimation process.
2. Distance Transform • We are using the DT as explained before. • We are using DT because of the observation that the dominant orientation of its gradients accurately reflects the skew of the document. (a) A portion of a text document image (b) The DT of the document image
3. Gaussian Blur • A Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function.
Why should we blur the image?? • Space between characters creates local maxima which is irrelevant to the document orientation and interrupts the statistics process that is being done later. • We would like to avoid those local maximas. • Blur will help us to eliminate local maxima between characters.
The blurring affect (c) Gradient orientation field of the DT (d) Gradient orientation field of the smoothed DT
4. Calculate the gardients • ds = smoothed DT image. • We now have to calculate the garident for each background pixel: • The gradient direction of ds can be approximated by:
5. Calculate Orientation • Why: • We would like to robustly estimate the orientation. • How: • For that matter, most methods divide the image into equal-sized windows and average the orientation in each window. • Problem : since the dominant orientation gradient vectors between text lines converge to the center of the gap from two opposite directions, they are expected to cancel each other. • For instance:
Solution • Before averaging we will double the angels of all pixels’ gradients. • i.e.: • Notice that the gradients are now pointing to the same direction. • Now we can obtain the orientation of block using: • Where:
We remember that is perpendicular to the text lines and thus: • As mentioned earlier, our method is based on the observation that the dominant orientation of the DT gradient vectors is perpendicular to text lines. • Now we will produce an histogram…
6. Histogram • In order to estimate the dominant orientation, we thus calculate a histogram, ,for the orientations obtained. • contains 18,000 bins to represent provides resolution of up to for a • The angle that corresponds to the peak of is the estimated skew angle : • )
(a) A document image rotated at 20◦. (b) Corresponding histogram hθ. (c) A document image rotated at −30◦. (d) Corresponding histogram hθ.
And Finally… • The Gaussian allow us to return an accurate value of the skew. • We return the Gaussian central value!