On Sat, Mar 31, 2012 at 12:24 PM, klo uo <klonuo@gmail.com> wrote:
While preparing some images for OCR, I usually discard those with low DPI, but as this happens often I thought to try some image processing and on suggestion (morphological operations) I tried ndimage.morph with idea to play around binary_dilation

Images were G4 TIFFs which PIL/MPL can't decode, so I convert to 1bit PNG which I normalized after to 0 and 1.

On sample img I applied:

ndi.morphology.binary_dilation(img).astype(img.dtype)

and

ndi.morphology.binary_erosion(img).astype(img.dtype)

I attached result images, and wanted to ask two question:

1. Is this result correct? From what I read today seems like what dilation does is erosion and vice versa, but I probably overlooked something

This result looks correct to me. I think it depends on what you consider "object" and "background": Typically (I think), image-processing operators consider light regions to be objects and dark objects to be background. So dilation grows right regions and erosion shrinks bright regions. Obviously, in your images, definitions of object and background are reversed (black is object; white is background).
 
2. Does someone maybe know of better approach for enhancing original sample for OCR (except thresholding, for which I'm aware)?

Have you tried the `open` and `close` operators? A morphological opening is just an erosion followed by a dilation and the closing is just the reverse (see e.g., the scikits-image docstrings). For an opening, the erosion would remove some of "salt" (white pixels) in the letters, and the dilation would (more-or-less) restore the letters to their original thickness. The closing would do the same for black pixels on the background. 
 
There are other approaches of course, but since you're already thinking about erosion and dilation, these came to mind

-Tony


TIA

Inline image 1

_______________________________________________
SciPy-User mailing list
SciPy-User@scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user