MATLAB: How do get a color region

color segmentationImage Processing Toolboximage segmentation

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

Best 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