MATLAB: Retrieving the lung pixels through matrix operations with images

Image Acquisition Toolboximage processingImage Processing Toolboximage segmentationmatrix manipulation

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?
>>

Best Answer

%This can do without for loop also, recomemded to follow the without loop
[rows colm]=size(rgb_image);
for i=1:rows
for j=1:colm
if (mask(i,j)==0) %Mask should be binary Image, if not convert it.
rgb_image(i,j,1)=0;
rgb_image(i,j,2)=0;
rgb_image(i,j,3)=0;
end
end
end
figure,imshow(rgb_image);
Related Question