using the attached color image and ROI mask and how can I remove the background from the image and retain only the approximate ROI.
3 ビュー (過去 30 日間)
古いコメントを表示
the color image must have the dark background in the output image.
0 件のコメント
採用された回答
Matt Gaidica
2021 年 12 月 12 日
IM = imread('ROI.png');
mask = logical(imread('mask.png'));
rmMask = bsxfun(@times, IM, cast(mask, 'like', IM));
close all
figure;
imshow(rmMask);
See also: Masking out Image area using Binary Mask
その他の回答 (1 件)
Image Analyst
2021 年 12 月 12 日
編集済み: Image Analyst
2021 年 12 月 12 日
Looks like you've accepted Matt's answer so you probably don't need this but
rgbImage = imread('ROI.png');
mask = logical(imread('mask.png'));
% Make mask 3-D
mask = cat(3, mask, mask, mask);
rgbImage(~mask) = 0;
I haven't tested it but that will probably work. If it's not your homework, try that.
If it's your homework then you may not be able to use imread(), cat(), logical(), imshow(), etc. so see this link:
and of course you wouldn't be able to use our code either - that would be even worse than using built-in functions and you could face disciplinary action.
4 件のコメント
Image Analyst
2021 年 12 月 12 日
OK, well if you run my demo with images called image1 and image2, it should look identical to the screenshot I posted in my last comment. If you alter it (like to handle your image names, or display things somewhat differently) and it doesn't work, then post your screenshot, two original images with the paperclip icon, and your code and I'll fix it.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!