12
$\begingroup$

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

enter image description here

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

enter image description here

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

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

which produced: enter image description here

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.

$\endgroup$
9
$\begingroup$

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.

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

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.)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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