How would you create a mask on an image?
Show older comments
I am doing a project and one of the tasks is to create a matrix with number of pixels x number of pixels x 3 as its size. In the previous task I created a matrix using the green container of the RGB image and I am suppose to duplicate this along the 3 dimensions. My question is what functions would I use in order to do this. I am not allowed to use any implicit functions only explicit.
6 Comments
Image Analyst
on 5 Oct 2013
Edited: Image Analyst
on 5 Oct 2013
Define implicit and explicit. Which are cat(), repmat(), bsxfun(), and class()? Walter and I used those in our Answers below. Are you allowed to use them?
Feynman
on 5 Oct 2013
Image Analyst
on 5 Oct 2013
That will get you a logical mask, m1, from which you can use it as the mask in my code below to mask out pixels brighter than the user specified value. You can set the values in any of the color channels to anything you want, e.g. 0 or 255, or anything else.
redChannel(m1) = 0; % Mask inside to %255 or whatever.
or
redChannel(~m1) = 0; % Mask outside.
Feynman
on 5 Oct 2013
Image Analyst
on 5 Oct 2013
mark and redChannel have to be the same type of integer like it said. So you'd need to do
maskedRed = redChannel .* uint8(mask);
if redChannel is a uint8.
Accepted Answer
More Answers (1)
Walter Roberson
on 5 Oct 2013
0 votes
repmat() or cat(3,X,X,X)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!