applying mask on an image
257 views (last 30 days)
Show older comments
Hello,
any help of how to write this code or how to start it?
Consider the “ctskull-256” image, apply a mask on it to only extract the
intensity above half of the peak intensity (that is, to set them to 1 and set
the pixel intensity below this level to 0). Compare the result with
FIGURE2.21(h) in your textbook, what do you find?
0 Comments
Answers (1)
Image Analyst
on 25 Sep 2019
To create a mask like you said:
maxGL = max(grayImage(:))
mask = grayImage > maxGL/2;
To apply the mask to an RGB image, use this code:
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
If it's grayscale, you can do it simpler like this:
grayImage(~mask) = 0;
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!