MATLAB: How to impose Binary mask on rgb color image

binary maskImage Processing Toolboximposemaskmaskingrgb color image

Hi i have threshold a rgb color image into binary image.
Now i want to impose this image onto my original image to get the purple cells and rest of the image remains black. Anyone have idea? Thanks a lot.

Best Answer

  • To mask an RGB image with a binary/logical image, simply do this:
    % Mask the image using bsxfun() function
    maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));