image-processingcomputer-visionimage-segmentationthresholdretina

Computer vision: how to remove circular white pixels after thresholding?


Good evening everyone, I have a small issue that intrigues me. I would like to remove the circle surrounding the retinal blood vessels to keep only the interior. Do you have any ideas? Thanks.

My image: Segmentation – This is the source image where I applied segmentation. I want to remove the large white circle.

Purpose: Ground_truth – This is my goal, it's the image I want to achieve after removing the circle.


Solution

  • Your image has a nasty white line around the edges - probably where you have screen-grabbed it rather than sharing your actual image. The first step is to remove that. Then you can do the following:

    Note that this technique can fail if your eye's circumference touches the edge of the frame because that prevents the flood-fill from flowing round the edges properly. If there is a risk of that, just add a 1px wide black border around the edges for the flood-fill to flow properly all the way around the edges and into the image from every point of every side. Then shave 1px off all sides when you are finished.


    I'll do the steps with ImageMagick separately and then all in one go. You can do the same with OpenCV, or wand or scikit-image. Here is an example of how to flood-fill with Pillow:

    # Shave 1 pixel off all edges
    magick YOURIMAGE -shave 1x1 step1.png
    

    enter image description here

    # Flood-fill with whote from top-left corner
    magick step1.png -fill white -draw "color 0,0 floodfill" step2.png
    

    enter image description here

    # Flood-fill with black from top-left corner
    magick step2.png -fill black -draw "color 0,0 floodfill" result.png
    

    enter image description here

    Or, all in one fell swoop:

    magick OlDlUKx1.png -shave 1x1 -fill white -draw "color 0,0 floodfill" -fill black -draw "color 0,0 floodfill" result.png