MATLAB: How i can seperate the determined area from the background in the image shown below then count the colours i have in the area using matlab ?.thanks

connected components labelingImage Processing Toolboximage segmentation

this is the image after doing watershed segmentaion

Best Answer

You can just get the max of the labeled image, then use ismember() to pull out the region you want
numRegions = max(labeledImage(:))
regionYouWant = 3; % Whatever number you want.
extractedRegion = ismember(labeledImage, regionYouWant);
Of course you can also get the number of regions from bwlabel() or bwconncomp() when you created the labeled image from the binary image:
[labeledImage, numRegions] = bwlabel(binaryImage);
It will be the same as taking the max of the labeled image.
Related Question