Skew Detection Using the Hough Algorithm

103 14
Many software applications (such as a photo indexer to create photo "albums", book scanning, document restoration and other examples) require their developers to implement robust algorithms for automatically detecting and correcting angular distortions of a scanned digitized image.
Ideally, these algorithms should have a low memory footprint and high performance.
However, conventional pixel-level methods approaches to this image processing problem (such as template matching and kernel convolution) are extremely processor-intensive once you deal with real, large size images (as a typical letter-sized sheet scanned at 300 DPI results in a 2550x3300 pixel image).
The Hough algorithm can detect different geometrical shapes, ranging from simple straight lines to more complex shapes (such as circles) while, at the same time, delivering good results at reasonably fast speeds for practical purposes.
Implementing the Hough algorithm for detecting straight lines, therefore, can provide us with an insight of the rotation or "skewing" our image contains.
In other words, if we detect that most straight lines are vertically skewed by 5 degrees, we could simply apply the same magnitude of rotation in the opposite direction in order to counter the undesirable distortion.
In practice, the following steps should be considered for implementing the Hough algorithm for straight line detection in your application:
  • Create accumulator: The Hough algorithm requires an "accumulator", which is basically an array of integers of dimensions [sqrt(NxN + MxM),180], being N x M the size of the original image and 180 being the degrees (spanning from zero to 180).
    Initialize all values to zero.
  • Inner loop: For each pixel of the original image, ask whether the pixel satisfies a spatial criteria or not and update the accumulator array accordingly.
    For example, in the case of straight line detection, we could ask whether the pixel is white, and, if this is the case, if the upper-positioned pixel is black.
    If both answers are affirmative, we can then say that this pixel is the spatial lower "bound" of a line, and the accumulator array should receive a "vote" for this pixel (incrementing its value by one).
  • Final detection: Navigate through the accumulator array and select the absolute maximum of votes (highest value in the array).
    The array's second index for this value gives the angle of the detected line; for example, if the highest value was found at (X,135) means that a line at 45 degrees was found (180-45=135).
Once the maximum value is found, applying an opposite rotation should be easy.
Further study of the accumulator array can give you additional insights, such as groups of lines found and their respective angles.
However, the Hough algorithm is not entirely devoid of problems.
We can single out both its merits and weaknesses: Pros: * Reasonably fast for practical purposes.
* Usually resistant to simple noise present in the original image.
Cons: * Granularity of the accumulator's angle index requires case-by-case experimentation.
* Medium memory footprint.
* High computational requirements (lower than typical template matching, however).
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.