필터 지우기
필터 지우기

How to create a mask on an image and have the background white?

조회 수: 8 (최근 30일)
Martha
Martha 2014년 9월 6일
댓글: Image Analyst 2017년 8월 14일
Hi, I create a mask into an image and I did this:
i=roipoly(f1,p1,p2);
mask=repmat(i,[1,1,3]);
f1(~mask)=1;
imshow(f1)
and it work very well but my problem is that I want to have the background white instead of black. How can I create a mask into an image, leaving a region of interest as it is (image) and all the rest as color white?
I appreciate some suggestions. Martha

채택된 답변

Image Analyst
Image Analyst 2014년 9월 6일
If f1 is a uint8 RGB image, you can set
f1(~mask) = 255;
See attached masking demo, attached below this image it creates:
  댓글 수: 5
Image Analyst
Image Analyst 2017년 8월 14일
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by