How to apply morphological operations like clearing border and removing small objects using matlab for color image?

I have a color image obtained after using k-means cluster and I want to apply morphological operations like cleaning border,filling holes and remove small object using matlab but thsese operation works only on grayscale or binar image in matlab! Any suggestions please!

Answers (1)

Since you seem to have a masked image, since large parts are perfectly black, you must already have a binary image mask. So just use it on that mask before applying the mask to the color image.

4 Comments

Well how did you get that image? Surely it was not perfectly black to begin with? You must have somehow used a mask to blacken areas. If you don't have a mask you can generate it from the masked RGB image like this :
mask = max(maskedRGBImage, [], 3) > 0;
In begin I have this image :
Then I applied k-means algorithm and I select this image as the suitable cluster:
After that, I want to select just the cell in the midst of the image and to extract the ocntour as the final step.
If you'd rather, then you can use the kmeans indexes and reshape to get the mask. See my attached demo.

Sign in to comment.

Asked:

on 16 Aug 2018

Commented:

on 21 Aug 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!