I want to keep a particular color in an image and discard all other colors. When I try to keep red color the program works but when I try a similar approach for green color I get nothing. Can anyone help. Below is my program. can't post images due to some reputation thing.
a = imread('image.jpg');
b = rgb2hsv(a);
h = 360 .* b(:,:,1);
s = b(:,:,2);
v = b(:,:,3);
nonred = (h > 20) & (h < 340);
v(nonred)=0;
b(:,:,3)=v;
c=hsv2rgb(b);
And here is the code for green color
a = imread('image.jpg.');
b = rgb2hsv(a);
h = 360 .* b(:,:,1);
s = b(:,:,2);
v = b(:,:,3);
nongreen = (h > 210) & (h < 30);
v(nongreen) = 0;
b(:,:,3)=v;
c=hsv2rgb(b);