필터 지우기
필터 지우기

how to do masking with the help of binary image?

조회 수: 5 (최근 30일)
Manoj Kumar
Manoj Kumar 2014년 11월 3일
답변: Image Analyst 2014년 11월 3일
Hi,
I have a binary image and using that binary image I wish to do masking.
Here is the binary image:
Using this binary image I want to mask to the original Image.
Here is the original Image:
I want the output as :
So, the output image should have the binary image portion and the remaining should be black("0").
Can you suggest me the code to do this.
Thanks...

채택된 답변

Guillaume
Guillaume 2014년 11월 3일
편집: Guillaume 2014년 11월 3일
repmat your binary image across the three colour channels and use the invert of that as logical index into your colour image to set the pixels to 0:
colourmask = repmat(binarymask, [1 1 3]);
maskedimage = colourimage;
maskedimage(~colourmask) = 0;

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 11월 3일
Here's a way that Sean recommends:
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));
It works for grayscale images too. I also attach some full demos, if you're interested.

Community Treasure Hunt

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

Start Hunting!

Translated by