applying mask on an image

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?

Answers (1)

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;

Asked:

on 25 Sep 2019

Answered:

on 25 Sep 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!