0

How to make a program in Mathematica that is able to recognize this image and return the radius of the circular part of it? enter image description here

1 Answers1

1

While curve extraction is possible the radius can be obtained quite simply, i.e.

img = Import["https://i.stack.imgur.com/LENuK.jpg"];
{wd, ht} = ImageDimensions[img];
data = ImageData[img];
p1 = LengthWhile[data[[-33]], # == {1., 1., 1.} &];
p2 = LengthWhile[Reverse[data[[-33]]], # == {1., 1., 1.} &];
p120 = wd - p1 - p2 - 1;
p3 = LengthWhile[data[[-245]], # == {1., 1., 1.} &];
p4 = LengthWhile[Reverse[data[[-245]]], # == {1., 1., 1.} &];
pdrop = wd - p3 - p4 - 1;
radius = 120/p120*pdrop/2.

55.814

Further automation could automatically detect the widest point of the drop, which is here found by testing: line 245 (see sample lines in bottom image).

Making sense of the scale could be difficult to automate. We can see the outermost ticks are at -60 & 60, a length of 120 which turns out to be 400 pixels, pdrop.

As the sketch below shows, the circular part of the drop is limited by the widest points, so that length and the scale are all that is needed to find the radius.

enter image description here

Two lines are used to find the image scale and outer bounds of the drop: line 33 and 245, shown below coloured red.

enter image description here

Additional code

In the code below r is calibrated against the scale so that it equals 60.

img = Import["https://i.stack.imgur.com/LENuK.jpg"];
{wd, ht} = ImageDimensions[img];

Manipulate[
 Graphics[{Rectangle[{0, 0}, {wd, ht}],
   Inset[img, {0, 0}, {0, 0}, {wd, ht}],
   Inset[Graphics[{Circle[{x, y}, r]},
     ImageSize -> {wd, ht}, PlotRange -> {{0, wd}, {0, ht}}],
    {0, 0}, {0, 0}, {wd, ht}],
   Inset[
    Style["r = " <> ToString[Round[60 r/212.8, 0.1]], 16],
    {50, 510}]},
  ImageSize -> {wd, ht}, PlotRange -> {{0, wd}, {0, ht}}],
 {{x, 228}, 0, 300}, {{y, 247}, 0, 300}, {{r, 196}, 0, 300}]

enter image description here

Chris Degnen
  • 8,443
  • 2
  • 23
  • 40
  • Thank you so much for your answer. I just didn't understand a part, what scale are you measuring the radius, pixels or millimeters? Also, would I be able to make the second part (the circle), so that it would give me the radius just by adjusting the circle inside the image? – Hinata Shoyo Jul 15 '22 at 23:07
  • 1
    I'll get back to you on that... – Chris Degnen Jul 15 '22 at 23:15
  • The radius is scaled to the axis on the image you provided. I have added another `Manipulate` in which the circle can be adjusted which displaying the radius. – Chris Degnen Jul 16 '22 at 10:09
  • I appreciate your feedback and your availability. Thank you very much! – Hinata Shoyo Jul 17 '22 at 01:46