MATLAB: How to select only the segmented region from a original image in MATLAB

crop imageimage analysisimage processingImage Processing Toolboximage segmentation

I need a little help.
I have a MATLAB code in which I've segment out an original image into multiple segments. Now I want to select only a specific segmented area and give it as an input to my function. I have attached my segmented image in which desired part is shown along with the black pixels. How do I select only the desired region, I don't want black pixels region.
Thanks,
for k = 1:max(max(l))
color = img;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
image = double(segmented_images{k})/255.0;
end

Best Answer

You could do,
S=regionprops(rgb_label,img,'Image')