how do get a color region?

I want to get something like like apple.jpg without using watershed.
How to get the color piece after I done edge detection, imclose and rgb2label.
My result is elephant.jpg how can turn it like apple.jpg

 Accepted Answer

You're going to have to use a better segmentation routine to get the elephant. Perhaps get gray things. Compute the HSV image from rgb2hsv() and look as the s image:
hsvImage = rgb2hsv(rgbImage);
sImage = hsvImage(:,:, 2);
% Binarize to find low saturation (gray) pixels.
binaryImage = sImage < 0.3;
That's just a guess, because you didn't attach the original RGB image. Elephants can sometimes blend in well with their surroundings so it might be tough to get it all, particularly if it's obscured by branches or other elephants or trucks or walls or whatever. If you get a noisy outline, you can clean it up with activecontour(), demo attached.
See my File Exchange which has several color segmentation demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

4 Comments

I using watershed now~how to merge the color together? I want to write a loop to loop through whole image and merge the nearby same color(maybe threshold +-10) to same label. How to do that?
The problem is that your initial segmentation, before watershed was even done, is no good. And watershed won't fix a bad segmentation. It'll just make even more bad segmentations (regions), as you've found out.
This is original image~can you show me how to get a good segmentation?
The code I gave you above should work to get the elephants in a colored background. There is a full blown demo on my File Exchange page: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
But I know of no way to have the program determine where one elephant starts and another stops. You could do edge detection, but the problem is there are going to be tons of edges everywhere, not just at the overlap line.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!