# Calculating the size of objects on the picture

I'm new to Wolfram Mathematica. I have an initial image:

My goal is to find a radius of the water drop, like so:

With that in mind, I've changed the initial photo:

resultImage = EdgeDetect[ImageResize[Binarize[Sharpen[//..here goes the image]], 2000]]


which produced:

To solve the initial problem, I suspect that I can use ImageData to convert the latter result into the corresponding matrix and manually process it row by row. But is there a more slick and convenient solution? What would you suggest? Thanks.

Here's a way that might work for you:

img = Import["https://i.stack.imgur.com/XekQw.png"]

imClip = ImageClip[img, {.9, 1}, {0, 1}];

coords = Position[MorphologicalComponents[imClip], 0];

possibilities = MinMax[#[[All, 2]]] & /@ GatherBy[coords, #[[1]] &];

Subtract @@
Reverse@MaximalBy[possibilities, Abs@*Apply[Subtract]][[1]]

303


I had to actually check what number MorphologicalComponents assigned to the black portions of the clipped image. That's where the 0 comes from.

Past that it's a pretty simple filtering, dependent on that bulge part being wider than any of the other parts.

Hopefully that's easier than what you had in mind.

• ComponentMeasurements with the "BoundingBox" property should be much more efficient than Position (which unpacks). – Alexey Popkov Oct 8 '17 at 23:16
• @AlexeyPopkov that was my first tack, but it turns out that bulge part isn't the furthest left it can go, I think. – b3m2a1 Oct 8 '17 at 23:18
• We can crop the image from the top with ImagePad in order to have only the bulge part. – Alexey Popkov Oct 8 '17 at 23:21

One way to proceed (that doesn't require searching through the rows) is to binarize the image, remove the top portion, and then crop. The width of the cropped image is the maximum width of the water drop.

img = Import["https://i.stack.imgur.com/XekQw.png"];
ImageCrop[ImageTake[Binarize[img], -550]] // ImageDimensions

{303, 387}


So it is 303 pixels wide.

(Thanks to Alexey for hint regarding an extraneous use of FillingTransform.)

• Probably FillingTransform isn't strictly necessary. (+1) – Alexey Popkov Oct 8 '17 at 23:29