필터 지우기
필터 지우기

How do I apply a mask to a gray image?

조회 수: 7 (최근 30일)
Adriano Morais
Adriano Morais 2016년 5월 9일
편집: Walter Roberson 2016년 5월 10일
Hey guys I'm trying to apply a mask to an image which I need to work on, I've tried to use the following code and didnt get what I need.
This is the image: http://imgur.com/flVD3Wn
And this is the mask Im trying to apply: http://imgur.com/rHuwzSH
I=imread('02_dr.JPG');
mask=imread('02_dr_mask.tif');
J=rgb2gray(I);
subplot(2,3,1); imshow(J), title('Original Grayscale');
subplot(2,3,4); imhist(J), title('Histograma 1');
subplot(2,3,2); imshow(mask), title('Mask');
subplot(2,3,5); imhist(mask), title('Histograma Mask');
% Mask the image using bsxfun() function
maskedImage = bsxfun(@times, J, cast(mask, 'like', J));
subplot(2,3,3); imshow(maskedImage), title('MaskedImage');
subplot(2,3,6); imhist(maskedImage), title('Histograma MaskedImage');
I have also tried the following instead of Inew = image.*repmat(mask,[1,1,3]);
Inew=image.*mask;

답변 (1개)

Image Analyst
Image Analyst 2016년 5월 9일
First of all, don't ever call your image "image" because that is the name of a very important built-in variable.
Try this:
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
  댓글 수: 4
Adriano Morais
Adriano Morais 2016년 5월 9일
I have uploaded my image, the mask, and the code.
Adriano Morais
Adriano Morais 2016년 5월 10일
So can you still help me?

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by