Wednesday, August 22, 2012

Act 8. Morphological operations application 1: Writing extraction

 Given the photo of a receipt shown below, we were tasked to crop an area and isolate the text.

Raw image
 After learning erode and dilate in the previous lesson, of course I was excited to put it to use!

After binarizing the cropped area, we erode it with horizontal structuring element. This must be longer than the length of one letter in the text, but it must be short enough so that the slight tilt of the lines would not pose a problem.

From the dilation, we get an image containing only the horizontal lines. Inverting this gives us a filter that is zero only on these lines. Multiplying this filter with the binarized image isolates the text. As a final step, we thin the image to make the letters one pixel thick simply by applying thin(Im).
(left) cropped are (middle) binarized image (right) isolated text
This code is limited in the sense that one would have to do additional masking(erosion, inversion, multiplication) to remove the vertical lines. This would not be a problem if we just edited the image in the frequency domain. (Remember this?)

Plus, since this code deletes all horizontal lines, it would erase part of the text if the text happened to intersect a horizontal line. This can be remedied a little by dilation of a short vertical structuring element.

Here's the code that takes the cropped picture and isolates the text. :)
Since I was successfully able to do the required task, I give myself a grade of 10/10.

No comments:

Post a Comment