How to convert the green pixels to white?

조회 수: 2 (최근 30일)
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 20일
댓글: Image Analyst 2016년 3월 21일
I have this image labelled dark green(In the image attached). I want to turn all of the pixels that are not black to white. How do i do that?

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 20일
%black pixels have 0 for all 3 components, R, G, B. So a non-black pixel has at least one non-0 component
mask = any(YourRGBImage,3); %true if any component is non-zero
%now that we know which ones are non-black, make those pixels white
%ah, short-cut: since logical true is 1 and white is 1, and logical false is 0 and black is 0
%we can just use the mask itself as the black / white image
maskedImage = double(repmat(mask, 1, 1, 3));
  댓글 수: 3
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 21일
syntax error. fixed it! thank you!
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 21일
편집: charuleelaa vanilavarasu 2016년 3월 21일
How do i do the reverse? i.e Turn all the black pixels white? would imcomplement work?

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

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 3월 21일
I hve several color segmentation demos in my File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Adapt one of them to find pixels that you consider to be of a roughly or exactly "green" color. This will give you a mask of what pixels are green.
If you really want to "I want to turn all of the pixels that are not black to white." then it really doesn't matter if they're green or purple or yellow or any other color to start with, does it? In that case, use Walter's code to turn non-pure-black pixels to white.
  댓글 수: 4
charuleelaa vanilavarasu
charuleelaa vanilavarasu 2016년 3월 21일
편집: Walter Roberson 2016년 3월 21일
Image1=im2double(filt);% filt is the filtered image
[row column page] = size(Image1)
mask = Image1(:,:,2) > Image1(:,:,1) & Image1(:,:,2) > Image1(:,:,3);
Image2 = Image1 .* mask(:,:,[1 1 1]);
figure,imshow(Image2);
title('light green');
mask = Image2(:,:,2) + 50 > Image2(:,:,1) & Image2(:,:,2) + 50 >
Image2(:,:,3);
Image3 = Image2 .* mask(:,:,[1 1 1]);
figure,imshow(Image3);
title('dark green');
This is what i used to get those pixels detected. It's supposed to detect vegetation in an image. Doesn't work perfectly but works to an extent.
Image Analyst
Image Analyst 2016년 3월 21일
You might be better off segmenting on hue in HSV color space. See the tutorial in my File Exchange.

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

카테고리

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