MATLAB: How can we map binary image on original RGB image

Image Acquisition Toolboximage processingmapbinarytorgb

I have an RGB image from which I extracted the desired part by converting it to binary image. Now, I want only the extracted part to be converted to their original RGB color. How can I do that?

Best Answer

Try this:
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
where mask is your binary image.