Page 1 of 1

Adding border only around filled area

Posted: 2020-03-26T09:58:35-07:00
by researcher
Hello,

I am trying to remove the grey oval/rectangle in an image, such as in the following image on the left, without affecting the text ("17 sec"):

https://i.postimg.cc/MGXqz2L0/original.png

The ovals are coloured #8b8b8f, so I tried filling that colour with white:

Code: Select all

convert original.png -fuzz 1% -fill white -opaque '#8b8b8f' new.png
But this leaves the oval edges:

https://i.postimg.cc/0Q2mkQsW/new.png

If I increase the fuzz any, the text is affected.

Is there a way to get rid of the oval edges too? Perhaps by using -floodfill (but without knowing the coordinates of the seed point in the oval)? Or filling then adding a border around the filled area?

Constraints: Each image has several ovals and the ovals vary in their length and position across the images.

Thank you!

Re: Adding border only around filled area

Posted: 2020-03-26T10:17:15-07:00
by fmw42
Your links are not going to any images that make sense for what you are describing.

Re: Adding border only around filled area

Posted: 2020-03-26T10:38:40-07:00
by researcher
I've edited the text to make it clearer — does it make sense now? The images should be of a grey oval/rectangle with the text "17 sec" beside it.

Re: Adding border only around filled area

Posted: 2020-03-26T11:58:53-07:00
by fmw42
You can use -connected-components to find each individual gray region in the image and get its centroid and then do a flood fill. You can identify the oval since it has the largest area of gray. I suggest thresholding first, then find the oval centroid. Then go back to the original and do your flood fill. Or better flood fill the thresholded image, use that as a mask to composite white in the original image. That way if it leaves a ring, you can use morphology to make the mask bigger where needed.

Re: Adding border only around filled area

Posted: 2020-03-26T13:11:33-07:00
by researcher
Thank you very much for the help. I was able to get it working with the following:

Code: Select all

convert original.png \
    \( +clone -fuzz 1% -fill white +opaque '#8b8b8f' \
    -define connected-components:area-threshold=10 \
    -connected-components 4 -white-threshold 1 \
    -transparent black -channel A -morphology EdgeOut Diamond +channel \
    +level-colors white \
    \) -composite -fuzz 1% -fill white -opaque '#8b8b8f'  \
    show:
(For some reason this does not work on the example images perhaps due to compression while saving, but it works on the originals.)