This is a bit of a follow-up to a previous question: How can I merge multiple sets of morphological components (perhaps selected using different metrics)?
I've run into a few problems recently where it's actually rather difficult to select morphological components in an image based on size or geometry metrics, and really it would be much easier to just click on them, or to select them based on a coordinate in their interior.
Consider the task of selecting an arbitrary subset of morphological components in this image:
Import["https://i.sstatic.net/gSXIj.png"]
Is something like this possible?
Here's an update based on nikie's comment, where I believe he's suggesting we can do this:
image = Binarize[Import["https://i.sstatic.net/gSXIj.png"]];
m = MorphologicalComponents[image];
m // Colorize
exMorphologicalComponentNumOne = PixelValue[Image[m], {50, 214}]
exMorphologicalComponentNumOneTEST = PixelValue[Image[m], {49, 213}]
exMorphologicalComponentNumTwo = PixelValue[Image[m], {206, 146}]
exMorphologicalComponentNumTwoTEST = PixelValue[Image[m], {203, 142}]
This, I believe, is telling us the index value for the morphological components containing the pixels at {50, 214} and at {206, 146} in the image. Here, PixelValue
simply takes a pixel coordinate and returns whatever is sitting at this index in ImageData[image]
. So if you look at the output for MorphologicalComponents[image]
, you'll notice that the matrix is the same size as the output from ImageData[image]
and that the positions in the image corresponding to a morphological component carry the value of the component's index.
This is a very good start (thank you nikie!), but it still isn't clear to me how to quickly select a subset of morphological components based on their index. It would also be really nice to be able to to the click-based selection I mention in the title, since here, we have to write down and retype coordinates using the locator pane. This becomes kind of time consuming if we need to select a large subset of morphological components in multiple images.
LocatorPane
, and your can usePixelValue
to get the pixel value of an image at that point. If you callPixelValue
onImage[MorphologicalComponents[binaryImage]]
, it'll give you the label index at that point. (Sorry, I don't have time for a full answer right now, but if you look at the documentation for these functions, you should be able to piece it together.) $\endgroup$