Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalents to OpenCV's erode and dilate in PIL?

I want to do some image OCR with PyTesseract, and I've seen that OpenCV's erode and dilate functions are very useful for noise removal pre-processing.

Since PyTesseract already requires PIL/Pillow, I'd like to do the noise removal in PIL, rather than get another library. Is there an equivalent to erode/dilate in PIL? (My research seems to suggest that MaxFilter and MinFilter could be used this way, but it's not fully clear to me if that's really true.)

Thanks!

like image 665
ROldford Avatar asked May 26 '17 06:05

ROldford


1 Answers

The best option is to use OpenCV python bindings. However, if you want to use PIL/Pillow, there is the ImageFilter Module: http://pillow.readthedocs.io/en/3.1.x/reference/ImageFilter.html

dilation_img = src_img.filter(ImageFilter.MaxFilter(3))
erosion_img = src_img.filter(ImageFilter.MinFilter(3))

The number 3 in the example is the mask size;

like image 121
Oliver Zendel Avatar answered Sep 21 '22 13:09

Oliver Zendel