Home > database >  Can morphology.remove_small_objects remove big objects?
Can morphology.remove_small_objects remove big objects?

Time:01-03

I was wondering if morphology.remove_small_objects could be used to remove big objects. I am using this tool to detect the objects as seen in the figure.

image with small objects,

However,there are big objects as seen in the left. Is there any way I could use morphology.remove_small_objects as a threshold, for example:

mask=morphology.remove_small_objects(maske, 30)

Could I use like a range? between 30 and 200 so I can ignore the red detection in the image. Otherwise, I will just count the white pixels in the image and remove the ones that have the highest.

CodePudding user response:

This might be a good contribution to the scikit-image library itself, but for now, you need to roll your own. As suggested by Christoph, you can subtract the result of remove_small_objects from the original image to remove large objects. So, something like:

def filter_objects_by_size(label_image, min_size=0, max_size=None):
    small_removed = remove_small_objects(label_image, min_size)
    if max_size is not None:
        mid_removed = remove_small_objects(small_removed, max_size)
        large_removed = small_removed - mid_removed
        return large_removed
    else:
        return small_removed
  • Related