7
$\begingroup$

I have many hundreds fundus images of the human eye.

Fundus image of human eye

The yellow arrow points to two spots which I I want to remove. The final result should be a perfect circle.

The removed area should be black.

I need this for image preprocessing for a machine learning project.

Any help would be great.

$\endgroup$
0

2 Answers 2

10
$\begingroup$

Find the largest morphological component:

m = SelectComponents[MorphologicalComponents[img, 0.1], "Area", -1];

enter image description here

Get the bounding circle (with radius multiplied by 0.98 to remove the blips)

circ = Flatten[{#[[1]], .98 #[[2]]} & /@ 
    ComponentMeasurements[m, {"Centroid", "BoundingDiskRadius"}][[All,2]], 1];
Show[img, Graphics[{Red, Thick, Circle[circ[[1]], circ[[2]]]}]]

enter image description here

mask = Show[Image[ConstantArray[0, Dimensions[ImageData[img]]]], 
  Graphics[{White, Disk[circ[[1]], circ[[2]]]}]]

enter image description here

newimg = ImageMultiply[img, mask]

enter image description here

$\endgroup$
8
$\begingroup$

I think it may be interesting to preprocess the image before using @Melago's approach.
This permits to get rid of the 0.98 coefficient.

One may say that the following preprocessing introduces a new "magic" coefficient (erosionRadius = 30), but this new coefficient is less critical than the 0.98.

img00 = Import["https://i.sstatic.net/kUebf.jpg"]  

enter image description here

img01 = MorphologicalBinarize[img00]  

enter image description here

erosionRadius = 30;
img02 = Erosion[img01, DiskMatrix[erosionRadius], Padding -> 0]  

enter image description here

m = Dilation[img02, DiskMatrix[erosionRadius]]    

enter image description here

Note that the top and the bottom are slightly flattened. This should not have effect on the extracted "BoundingDiskRadius"

Beyong this point, @Melago's approach is used :

circ = Flatten[{#[[1]], (* 0.98 : Removed *) #[[2]]} & /@ 
    ComponentMeasurements[m, {"Centroid", "BoundingDiskRadius"}][[All,
       2]], 1];
Show[img00, Graphics[{Red,Thick,Circle[circ[[1]], circ[[2]]]}]]  

enter image description here

Related

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.