[SciPy-User] ndimage/morphology - binary dilation and erosion?

Tony Yu tsyu80@gmail....
Sat Mar 31 11:48:40 CDT 2012


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<http://scikits-image.org/docs/dev/api/skimage.morphology.html#greyscale-open>).
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
>
> [image: Inline image 1]
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120331/0c328aef/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 11309 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20120331/0c328aef/attachment-0001.png 


More information about the SciPy-User mailing list