8
$\begingroup$

I have produced this image by applying a Gaussian image substraction, Binarize, Colornegate, and MorphologicalComponents to the original image:

enter image description here

As you can see by the different colors, the colored parts are mostly separate, and consist of a fairly thin but very winding pieces (if you could take one and lay it out to be straight, it would have a fairly high aspect ratio). I'm interested in finding a way to characterize the "thinness" of the pieces that make up the image, so that I could make a histogram of it.

Obviously the width I'm talking about changes along the length of each of those pieces, so I would be fine with some sort of average.

I'm kind of looking for something similar to the Convex Hull properties of ComponentMeasurements, like the Width property, but that does the border that surrounds the whole object, and also includes some space outside of the piece, if they're shaped like mine (if I'm understanding the concept correctly).

I can think of a few ways, but they'd pretty bad. One would be to chop up this picture into an ensemble of smaller ones, where the different pieces in each one would be more elliptical, and then use the properties of the best fit ellipse of ComponentMeasurements[].

Another way I can think of is to adjust my Binarize threshold so that more of the pieces become separate, and then use the ellipse properties again, and then I guess do an adjustment to see how much material was lost in doing that, and compensate for it, if that makes any sense. However, it's also pretty messy and inaccurate.

Another way maybe: replace each piece with a series of connected circles, similar to in the following picture, then just use the radii of the circles. However, it's a little past my abilities, so I don't know if it's possible:

enter image description here

edit: I've tried the last method and got it to work, kind of:

enter image description here

(I zoomed in on part of my original image because the circles were making it unclear at the original magnification.) It works pretty well: the circles, for the most part, cover most of a given piece, and not too much outside the piece.

I would still love to hear any better methods. This one has some possible flaws, like extraneous circles being added and throwing off the numbers.

Does anyone know of a better way to do this?

Thanks!

$\endgroup$
1
  • $\begingroup$ To characterize the "thinness of the pieces that make up the image" how about the ratio of the perimeter to the area of each piece. These can be extracted directly using ComponentMeasurements. $\endgroup$
    – bill s
    Aug 4, 2015 at 19:41

1 Answer 1

8
$\begingroup$

You could use the mean distance from the boundary, which for a long thin object is about 1/4th of its width.

image = Import["https://i.stack.imgur.com/2G491.png"];
m = MorphologicalComponents[image];
d = DistanceTransform[image];
widths = ComponentMeasurements[{m, d}, "Mean"]
(* {1 -> 2.40336, 2 -> 5.08581, 3 -> 2.7668, ... } *)

Here are the original components coloured by "width":

Image[Raster[Replace[m, widths, 2], ColorFunction -> "SunsetColors"]]

enter image description here

Using "Max" instead of "Mean" gives slightly different results:

enter image description here

The choice is whether you want to consider a long thin piece with one thick bulb attached to count as thin or thick.

$\endgroup$
1
  • 3
    $\begingroup$ +1. If you only want the local maxima of the distance transform, you can use SkeletonTransform. If Mean/Max are not enough, you can use ComponentMeasurements[... "Data" to get the pixel values in the distance transform/skeleton image. $\endgroup$ Jan 9, 2015 at 8:53

Your Answer

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

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