How do I create an RGB image mask using a 2-D logical matrix?
Show older comments
I am trying to create an image mask using a logical 2-D matrix as the mask. The 3-D image matrix and the 2-D mask matrix are the same dimensions. Wherever the logical mask is true, I want to keep the image as is. Where the mask is false, I want to change the intensity of the image. How do I go about doing this?
Here is my attempt so far:
[ maskedImage ] = maskImage( input_image, mask_image )
red = input_image(:, :, 1);
green = input_image(:, :, 2);
blue = input_image(:, :, 3);
if mask == 1
input_image(:, :, 1) = red;
input_image(:, :, 2) = green;
input_image(:, :, 3) = blue;
else
input_image(:, :, 1) = red .* 0.3;
input_image(:, :, 2) = green .* 0.3;
input_image(:, :, 3) = blue .* 0.3;
end
maskedImage = input_image;
end
I know that my indexing is incorrect, because I want to change the values in the image matrix where the values in the mask matrix are false, but I don't know how. I apologize if this has been asked, but I could not find an answer regarding a transparent mask.
Answers (1)
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!