# Detecting an ellipse in a glaucoma photo

For glaucoma diagnosis it is common to determine a "cup to disk ratio" which compares the diameter of the optic disk (VDD) and optic cup (VCD). The optical disk is visible as a circular red feature (red channel) and the optic cup shows up as a yellow circle (green channel). How can I calculate the diameter ratio between optic disk and optic cup?

I am able to detect the optic disk with canny edge detection, but I have not found a way to calculate the cup to disk ratio. How might I do that?

• Can you provide sample images (without labeling) for experimentation? – kirma Nov 16 '15 at 12:53
• Is your question more about how to automatically find the ellipse pattern in an image? or about fitting an ellipse at a starting point in an image? or more about calculating the size of the ellipse? Please provide a minimal example. – Thies Heidecke Nov 16 '15 at 12:55
• You may also check this answer for ellipse fitting. mathematica.stackexchange.com/questions/25589/… – s.s.o Nov 16 '15 at 13:04
• how about calculating the diameter between optic disk and optic cup? sorry my first question is not complete. i have already detect the optic disk with canny edge detection, but i have not found a way to calculate the diameter of optic disk and optic cup. How might I do that? – indra ginanjar A.T Nov 16 '15 at 16:44
• @kirma - Additional info and test images for glaucoma and related eye problems: optic-disc.org – dionys Nov 17 '15 at 12:40

Fitting an ellipse:

i = Import["http://i.stack.imgur.com/W7HJk.jpg"];
lineByCenter[center_, semi_, angle_] := Rotate[Line[{#1 - #2, #1 + #2}], angle, #1]&
[center,{0,semi}]
sa    = 1 /. ComponentMeasurements[ Binarize@i, "SemiAxes"]
angle = 1 /. ComponentMeasurements[ Binarize@i, "Orientation"]
bbc   = Mean /@  Last /@ ComponentMeasurements[ Binarize@i, "BoundingBox"] // First
Show[i, Graphics[{Thick, White, Rotate[Circle[bbc, sa], angle, bbc],
Blue, lineByCenter[bbc, sa[[1]], angle + Pi/2],
Green, lineByCenter[bbc, sa[[2]], angle]}]]


edit

In your previous and now closed question you asked for a yellow "cup" and a red "disk".The problem is that the "cup" barely resembles a same-center ellipse, so you need to define some additional criteria.Look:

i = Import["http://i.stack.imgur.com/W7HJk.jpg"];
s = ChanVeseBinarize[i, "TargetColor" -> {Yellow, Red}];
ImageMultiply[i, ColorNegate@s]


edit2

After some googling I got convinced that the "cup" isn't really constrained to be a co-centered ellipse and the relevant parameters for the diagnosis/prognosis aren't just size measurements, but also the relative position of both components:

• what this is code for matlab? because im using matlab. can you give example using matlab code – indra ginanjar A.T Nov 18 '15 at 15:19
• @indraginanjarA.T This site is specific for Mathematica. You may post Matlab questions at stackoverflow.com – Dr. belisarius Nov 18 '15 at 15:29
• @indra, it's not our fault that you didn't bother to check that you were asking at an appropriate site. – J. M. will be back soon Nov 19 '15 at 1:58

If you need more precise calculation you may check this answer.

cm = ComponentMeasurements[Binarize@img, "BoundingDiskRadius"]
ct = 1 /. ComponentMeasurements[Binarize@img, "BoundingDiskCenter"];
Show[img, Graphics[{Thick, White, Circle[ct, cm[[1, 2]]]}]]


{1 -> 63.4933}