Any MATLAB codes to convert an image into grayscale but keep only the green color from the image.
What I want to be my output is to keep the green color from the image and the rest is still gray
Any MATLAB codes to convert an image into grayscale but keep only the green color from the image.
What I want to be my output is to keep the green color from the image and the rest is still gray
If you mean that you want to simply preserve the green component of the image, you can simply set the R and B components of the image to zero.
To do so, simply load the image, say, in variable my_image
, and simply do the following:
>> my_image = imread('lena.bmp');
>> imshow(my_image);
Now,
>> [x, y, z] = size(my_image);
>> my_image(:,:,1) = zeros(x,y);
>> my_image(:,:,3) = zeros(x,y);
>> imshow(my_image);
The result would be something like below:
If you want to display the green as grayscale, you could just do the following though:
>> my_image = imread('lena.bmp');
>> imshow(my_image(:,:,2));