Retrieving the lung pixels through matrix operations with images
Show older comments
I have two images, an original CXR, and its corresponding lung mask. I would like to perform an operation with these two images, to generate only the lung ROI from the original CXR and make the rest of the background black. The resultant image should be in RGB as the original CXR and mask, and not grayscale or binary. I tried performing bitwise multiplications and X-OR operations but doesn't work. Can you suggest me the code to do this?


>>
1 Comment
KALYAN ACHARJYA
on 11 Aug 2018
I have edited the answer, Have you check? Please confirm?
Accepted Answer
More Answers (1)
Image Analyst
on 10 Aug 2018
Edited: Image Analyst
on 10 Aug 2018
This should work
maskedRgbImage = originalImage; % Initialize
% Convert to RGB, if needed.
[rows, columns, numberOfColorChannels] = size(maskedRgbImage);
if numberOfColorChannels == 1
maskedImage = cat(3, maskedRgbImage, maskedRgbImage, maskedRgbImage);
end
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
% Will work regardless if it's grayscale or color.
maskedRgbImage = bsxfun(@times, maskedRgbImage, cast(mask, 'like', maskedRgbImage));
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!