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

查看:35
本文介绍了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天全站免登陆