简体   繁体   English

如何从图像中删除工件(OpenCV、Python)

[英]How to remove artifacts from image (OpenCV, Python)

I have the following image (see below) which I am trying to preprocess in order to remove all form text and keep handwritten inputs.我有以下图像(见下文),我正在尝试对其进行预处理,以删除所有表单文本并保留手写输入。 I'm doing all preprocessing in python using PIL and OpenCV.我正在使用 PIL 和 OpenCV 在 python 中进行所有预处理。 Which filters can I use to remove the noise from my image?我可以使用哪些过滤器来去除图像中的噪点?

图片

Assuming the images are BGR or grayscale (not binary) and that the color of the pen used to fill the document is atleast slightly different then the printed text.假设图像是 BGR 或灰度(不是二进制),并且用于填充文档的笔的颜色至少与打印文本略有不同。 Probably the only way to do this is to cluster the colors of the image in to two clusters, one cluster will be the color of the pen and the second will be the color of the text, For clustering you can use Kmeans Algorithm with k=2.可能唯一的方法是将图像的颜色分为两组,一组是笔的颜色,第二组是文本的颜色,对于聚类,您可以使用Kmeans算法和 k= 2.

Using ImageMagick, one can do the following.使用 ImageMagick,可以执行以下操作。 You can probably get similar functionality from Python Wand, which is based upon ImageMagick.您可能可以从基于 ImageMagick 的 Python Wand 获得类似的功能。

Input:输入: 在此处输入图片说明

Make a copy of the image.制作图像的副本。 Then invert it (negate) and blur it.然后反转它(否定)并模糊它。 Then threshold it.然后阈值它。 Then put that into the alpha channel of the input.然后将其放入输入的 alpha 通道中。 Then flatten it over a white background.然后将其压平在白色背景上。

convert image.png -alpha off \
\( -clone 0 -negate -blur 0x2 -threshold 50% \) \
-alpha off -compose copy_opacity -composite \
-background white -compose over -flatten \
result.png


在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM