When I ask ComponentMeasurements
to return "IntensityData" for some set of rectangular morphological components:
m = MorphologicalComponents[image, Method -> "BoundingBox"];
intensityDataArray = ComponentMeasurements[{m, image}, "IntensityData"][[All, 2]];
The pixel value data is returned as an unpartitioned one-dimensional array. This makes it difficult for me to understand where a particular pixel is in the image. Now, if I know the exact dimensions of each morphological component, I suppose I could fix the problem using Partition
. I could also fix the problem with Partition
if I could ask for something like a bounding square instead of a bounding rectangular box, though I don't think this is possible (is it?).
Besides manually measuring the dimensions of each rectangular morphological component, is there a workaround to fix this problem?
Letting m
consist of strictly rectangular morphological components, it would, for example, be very nice to be able to write something like:
ComponentMeasurements[m, "Dimensions"][[All, 2]]
And have this return something like:
{{5,8}, {87, 40}, {7, 7}, ...}
Meaning that we have morphological components of dimensions $(x, y) = (5 \times 8)$, $(87 \times 40)$, $(7 \times 7)$, and so forth. Here, we're provided ordered values for the extent of the component along the $x$- and $y$-axes, respectively, allowing us to trivially use Partition
to restore the cropped section of an image underlying a morphological component (i.e. the image one would have if a morphological component is used as a "cropping mask").
Clarification: Masking approaches are really neat, but not quite what I'm looking for here unless they're part of a larger approach. I need a method of grabbing the pixel data strictly underlying a morphological component (for a set of morphological components) and retaining $(x, y)$ data for each pixel. My downstream procedure then does further image processesing on this rectangular matrix. If I do a matrix multiplication masking procedure, I still need to trim away the dark space to get down to a bounding box (the size of the morphological component mask).
Also, it seems a little wasteful to have to perform multiplication operation on all pixels in the image to accomplish my goal?
"IntensityData"
is meant to be used for histogram processing, where the position of the intensities doesn't matter. Couldn't you just measure the"BoundingBox"
instead and pass the result toImageTrim
to cut out the right area of the image? You can measure"Mask"
to get a sparse array where the pixels of the component are set to 1. (I'm not sure what you're trying to achieve, I that's what I use when I need both the intensity and the location of the pixels in a component.) $\endgroup$