Reputation: 3641
I'm running an algorithm to segment part of an image using morphological operations. I end up with a 2D binary image that represents the segmentation results. Namely, the mask. My question is how to plot the original image and the mask overlay in color on top of it.
Thank you.
Upvotes: 2
Views: 7426
Reputation: 2571
Using imoverlay
is fine, I do so myself, but often I want a transparent composite. It's convenient to have this in a single array as it makes saving the image a bit easier.
alpha = repmat(0.35 * mask,[1 1 3]);
labels = label2rgb(bwlabel(mask));
im3 = repmat(im,[1 1 3]); %# Assuming image is grayscale
overlay = ( (1-alpha) .* im3 ) + ( alpha .* labels );
imshow(overlay); %# Or imwrite, etc.
Upvotes: 2