【问题标题】:Equivalents to OpenCV's erode and dilate in PIL?相当于 OpenCV 在 PIL 中的腐蚀和扩张?
【发布时间】:2017-10-26 23:02:24
【问题描述】:

我想用 PyTesseract 做一些图像 OCR,我已经看到 OpenCV 的 erode 和 dilate 函数对于去噪预处理非常有用。

由于 PyTesseract 已经需要 PIL/Pillow,我想在 PIL 中去除噪音,而不是获取另一个库。 PIL 中是否有等效于腐蚀/扩张的方法? (我的研究似乎表明 MaxFilter 和 MinFilter 可以以这种方式使用,但我并不完全清楚这是不是真的。)

谢谢!

【问题讨论】:

  • 是的,最小值/最大值是等价的

标签: python-imaging-library pillow python-tesseract


【解决方案1】:

最好的选择是使用 OpenCV python 绑定。但是,如果您想使用 PIL/Pillow,则有 ImageFilter 模块: 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))

示例中的数字 3 是掩码大小;

【讨论】:

  • 您为什么认为 OpenCV 是“最佳选择”?这个操作比 Pillow 快吗?
  • OpenCV 更适合去噪或更高级的操作,因为它的重点是计算机视觉。关于速度:取决于版本和操作系统,但总的来说,OpenCV 中的所有操作都比 Pillow 中的更快(OpenCV 中通常也有专用的 GPU 版本):kaggle.com/vfdev5/pil-vs-opencv
猜你喜欢
  • 1970-01-01
  • 2023-02-02
  • 2020-03-19
  • 1970-01-01
  • 1970-01-01
  • 2013-06-24
  • 2012-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多