How do I remove text and markings from the below medical ultrasound image?
When applying an inpainting algorithm using OpenCV we need to provide two images: The input image with the text we want to remove. The mask image, which shows where in the image the text that we want to remove is. This second image should have the same dimensions as the input.
Click 'Shift+Backspace,' and it will open the Fill window. Now choose the option of 'content-aware and click Ok. Doing this will remove the text, and all you've to do is click 'Ctrl+D. ' You're good to go.
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)
Here's the mask:
Here's the inpainted image:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With