필터 지우기
필터 지우기

How can I apply a logical mask to an image variable?

조회 수: 8 (최근 30일)
dila suay
dila suay 2022년 2월 24일
댓글: Kaitlin Wang 2022년 2월 24일
Hello,
I am trying to apply a logical mask to an image variable, however I couldnt manage to do it so far.
I have tried
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
maskedRgbImage = rgbImage.*mask
Also, I've tried to apply mask to the rgbImage.CData directly. All of them are giving me errors. What else I can try?
Thank you so much
  댓글 수: 2
Walter Roberson
Walter Roberson 2022년 2월 24일
Your rgbImage is a handle to a deleted image() object -- not an array of data.
dila suay
dila suay 2022년 2월 24일
Hi Walter, thank you for your quick reply. I uploaded a .fig version. I hope it is useful

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 24일
rgb = rgbImage.CData;
maskedImage = rgb .* cast(repmat(c, [1 1 size(rgb,3)]),'like',rgb);
This cannot be an image() object unless you want to do something like
maskedRgbImage = copyobj(rgbImage, gca);
rgb = rgbImage.CData;
maskedImage.CData = rgb .* cast(repmat(c, [1 1 size(rgb,3)]),'like',rgb);
... but that would be directly on top of the old image.
  댓글 수: 2
dila suay
dila suay 2022년 2월 24일
Thank you so much for your quick replies Walter. It says
Unrecognized function or variable 'c'.
What is c?
Walter Roberson
Walter Roberson 2022년 2월 24일
rgb = rgbImage.CData;
maskedImage = rgb .* cast(repmat(mask, [1 1 size(rgb,3)]),'like',rgb);
or
maskedRgbImage = copyobj(rgbImage, gca);
rgb = rgbImage.CData;
maskedImage.CData = rgb .* cast(repmat(mask, [1 1 size(rgb,3)]),'like',rgb);

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

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 2월 24일
You don't need to do both of these:
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
maskedRgbImage = rgbImage.*mask
All you need is the first one. Don't do the second one. It's not right and would need "fixing".
  댓글 수: 1
Kaitlin Wang
Kaitlin Wang 2022년 2월 24일
sir you are my hero. i have been looking at your answers for weeks and learning so much. thank you

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by