Which Set of Morphological Operations should I use?
4 views (last 30 days)
Show older comments
I have a very set of images that I am trying to segment. I am trying to use morphological operations to make my segmentation look cleaner. My segmentation algorithm is currently using Kmeans clustering, based on two selected regions.
The output looks like these images:
Sometimes the output only needs a small bit of refinement: Here I just need to smooth down the edges, and remove a few outside artifacts and fill in a few small gaps.

Other times, the output needs much more work: Here a large amount of outside artifacts need removed and a large gap needs filled in.

So far, I have used imerode and imdilate, as well as imclose and imopen. But, I'm confused about the order of how to use them and which structuring element (shape and size) would work best.
Is a standard set of morphological operations (done in any particular order) to remove outside pieces and fill in the image? Also, what structuring element shape & size would be best for my application? The image sets are not all the same, some are square, some are more round, others are entirely elliptical.
Thanks in advance!
0 Comments
Answers (1)
Image Analyst
on 25 Jan 2015
It looks like you have a candidate binary mask which is white/1/true inside the spot and black/0/false outside the spot. So, to smooth it.
binaryImage = imclose(binaryImage, true(11)); % Adjust 11 depending on how smooth you want it.
You might be able to get a smoother one with less artifacts if you just blur it with conv2() and then threshold
blurredImage = conv2(double(binaryImage), ones(11), 'same');
binaryImage = blurredImage > 0.5;
Then to extract the largest blob only, use
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, numberToExtract);
%---------------------------------------------------------------------------
ExtractNLargestBlobs() is in the attached demo.
2 Comments
Image Analyst
on 25 Jan 2015
You can use structuring elements of different shapes. Check out the strel() function. Of course anything you do will distort the shape, but that's what you want. An alternative to morphological methods is active contours. I've attached a demo for that.
See Also
Categories
Find more on Image Segmentation and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!