MATLAB: How can i change rgb picture to red or green or blue

rgb to red

I need to transform rgb picure to red color or green color or blue color How can i do this?

Best Answer

You can't use mean directly, because it changes your data type to double. I am assuming you mean that you want to convert your image to grey scale and then use that as the red channel.
%first, make an empty 3-color copy of your image, preserving data type

NewIm=OldIm*0;
%second, copy the mean value to one color channel
NewIm(:,:,1)=mean(OldIm,3);
Edit:
The second option of what you could mean is this:
%first, make an empty 3-color copy of your image, preserving data type
NewIm=OldIm*0;
%second, copy the one color channel
NewIm(:,:,1)=OldIm(:,:,1);
Related Question