OpenCV-从图像中删除文本 [英] OpenCV - Remove text from image

查看:396
本文介绍了OpenCV-从图像中删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从下面的医学超声图像中删除文本和标记?

How do I remove text and markings from the below medical ultrasound image?

推荐答案

在大多数情况下,该阈值可对白色区域进行遮罩,然后进行修补.

Thresholding to make a mask of the whiter areas and then inpainting will work for most cases in this image.

img = cv2.imread('ultrasound.png')
mask = cv2.threshold(img, 210, 255, cv2.THRESH_BINARY)[1][:,:,0]
dst = cv2.inpaint(img, mask, 7, cv2.INPAINT_NS)

这是面具:

这是已修复的图像:

请注意,阈值掩码不正确,并且包括较浅的区域(没有字母).但更重要的是,如果蒙版不包含需要删除的区域(例如,中间的十字阴影),则尤其会产生问题.这是该区域的放大图.

Notice the thresholding mask is not exact, and includes lighter regions where there are no letters. But more importantly, there is especially an issue if the mask does not include regions that need to be removed, such as the dark shadows of the crosses in the middle. Here's a zoom-in of that region.

遮罩只是白色区域,不覆盖黑暗区域.对于阈值不足的此类问题,可以手动调整遮罩.在这里,我将原始的十字架放在蒙版中并移动以覆盖阴影,并且修复效果要好得多. (同样,如果需要,可以手动删除不应该包含在遮罩中的区域)

The mask is just of the white region, and doesn't cover the dark areas. For problems like this where thresholding will not be enough, the mask can be adjusted manually. Here I take the original crosses in the mask and shift to also cover the shadows, and the inpainting is much better. (Similarly, if needed, the areas that shouldn't be included in the mask can be manually removed)

crosses = mask[235:267,290:320] | mask[233:265,288:318]
mask[235:267,290:318] = crosses
dst = cv2.inpaint(img, mask, 7, cv2.INPAINT_NS)

这篇关于OpenCV-从图像中删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆