I'm not sure of exactly what you are after with your question, but the code below may help you in achieving the result. If you leave a comment, I can perhaps improve the answer.
0) Read in an image in RGB format.
First option: Separate out green and other components (each plotted separately), and make a final plot of all non-green components set to 1. Note: this results in a fully black image as all components have some amount of green.
Second option: Separate the image into either Red, Green or Blue based on the maximum contribution. The last plot shows the conversion to black and white. Note: The algorithm is not vectorized so this would be slow if processing large/many images.
I = imread('autumn.tif');
IG = I; IG(:,:,[1 3]) = 0; % Green only
INoG = I-IG;
INoG1 = INoG; INoG1(abs(INoG1) > 0) = 1;
% Possibly what you want?
% Display resulting images
subplot(4,2,1)
imshow(I)
title('Original');
subplot(4,2,2)
imshow(INoG)
title('No Green');
subplot(4,2,3)
imshow(IG)
title('Only Green');
subplot(4,2,4)
imshow(INoG1)
title('No Green (all 1?)');
% Note: There is a bit of each color in every pixel...
% => Potential solution: Use major contributor
% Not vectorized => Slow for large images
IRGB = I*0;
for i = 1:size(I,1)
for j = 1:size(I,2)
[~,k] = max(I(i,j,:));
if (size(k) > 1)
k = k(1);
end
IRGB(i,j,k) = 255;
end
end
IRGBG = IRGB; IRGBG(:,:,[1 3]) = 0; % Green only
IRGBNoG = IRGB-IRGBG;
BandWNoG = IRGBG(:,:,2); % Possibly what you want?
% Display resulting images
subplot(4,2,5)
imshow(IRGB);
title('RGB - Original');
subplot(4,2,6)
imshow(IRGBNoG);
title('RGB - No Green');
subplot(4,2,7)
imshow(IRGBG);
title('RGB - Only Green');
subplot(4,2,8)
imshow(BandWNoG)
title('Black and White - No Green');