image processing - How can I merge multiple sets of morphological components (perhaps selected using different metrics)?
Let's say I use SelectComponents
to select morphological components in an image according to some criterion, like "Elongation". Then let's say, I pull out a different set of morphological components using another criterion like "Area".
m1 = SelectComponents[testImage, "Elongation", # == 1 &];
m2 = SelectComponents[testImage, "Area", # > 42 &];
How can I properly merge m1
and m2
into a single set of non-intersecting morphological components?
Answer
You can combine the outputs of SelectComponents
in a straightforward way. Let's take a test image from the docs:
c=Import["http://i.stack.imgur.com/gSXIj.png"]
and select two conditions on the components:
m1 = SelectComponents[c, "Elongation", # > 0.5 &];
m2 = SelectComponents[c, "Area", # < 1000 &];
These m1
and m2
are binary images with 1's where the criterion is fulfilled and 0's where it fails.
{m1,m2}
You can find the intersection of the two components by multiplying
ImageMultiply[m1,m2]
You can find the union of the two selected components by adding (for binary images, ImageAdd
is essentially the logical OR of the two images)
ImageAdd[m1, m2]
Comments
Post a Comment