using the attached color image and ROI mask and how can I remove the background from the image and retain only the approximate ROI.

조회 수: 8 (최근 30일)
the color image must have the dark background in the output image.

채택된 답변

Matt Gaidica
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);
  댓글 수: 1
Nosipho Majola
Nosipho Majola 2021년 12월 12일
편집: Nosipho Majola 2021년 12월 12일
Thank you Matt. Would you please help me out with a code that does not use built-in functon but still does the same thing? i.e. not using bsxfun()

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
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
Nosipho Majola
Nosipho Majola 2021년 12월 12일
@Image Analyst I did run the previous code you had given and the output image was not the one I was expecting, which is the one written "masked image" in this new code.
about the function, I did see that yours does not have it. it just that the output image was different from the one required.
i am about to try the edited one now, thank you.
Image Analyst
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by