
Question:
I have labeled an binary image <img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/3ILgh.png" data-original="https://i.stack.imgur.com/3ILgh.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
imageLabels = morphology.label(imageBinary, background=255)
However when I check the number of labels, I get 535 elements.
print(len(imageLabels))
As a solution for this I thought about using measure.regionprops
in order to remove the labels with a small pixel area. How would you guys approach this? I have tried the following, but for one reason or another the new array is no longer seen as a correct label element.
i=0
for labelprop in measure.regionprops(imageLabels):
if (labelprop.area > 100):
imageLabels_keep.append(imageLabels[i])
i=i+1
Answer1:I think morphology.remove_small_objects(image, min_px_size)
does what you're looking for. Here's an example that uses that function:
<a href="http://scikit-image.org/docs/dev/auto_examples/applications/plot_coins_segmentation.html#edge-based-segmentation" rel="nofollow">http://scikit-image.org/docs/dev/auto_examples/applications/plot_coins_segmentation.html#edge-based-segmentation</a>