Retrieving the lung pixels through matrix operations with images
1 回表示 (過去 30 日間)
古いコメントを表示
Sivaramakrishnan Rajaraman
2018 年 8 月 10 日
コメント済み: Sivaramakrishnan Rajaraman
2018 年 8 月 13 日
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193537/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193538/image.jpeg)
>>
1 件のコメント
採用された回答
KALYAN ACHARJYA
2018 年 8 月 10 日
編集済み: KALYAN ACHARJYA
2018 年 8 月 11 日
%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);
9 件のコメント
Image Analyst
2018 年 8 月 11 日
Hmmmm. Not sure why. Here's a fully working example.
originalImage = imread('peppers.png');
subplot(2, 2, 1);
imshow(originalImage);
axis('on', 'image');
[rows, columns, numberOfColorChannels] = size(originalImage);
% Make mask
mask = false(rows, columns);
mask(100:300, 100:400) = true;
subplot(2, 2, 2);
imshow(mask);
axis('on', 'image');
maskedRgbImage = originalImage; % Initialize
% 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));
subplot(2, 2, 3);
imshow(maskedRgbImage);
axis('on', 'image');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194090/image.png)
その他の回答 (1 件)
Image Analyst
2018 年 8 月 10 日
編集済み: Image Analyst
2018 年 8 月 10 日
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));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!