MATLAB: Changing colors in an image

colorimage processingImage Processing Toolbox

Hi Guys,
I have a 1024*1024*3 size .tif picture. The main colors in it are white, black and green. I want to reverse the colors black and white and change green to red. Can anyone tell me how i can do that?
Thanks Nancy

Best Answer

Try this:
% Construct the rgb image with swapped red and green channels.
thresholdValue = 5; % How much greener does it need to be?
greenishPixels = (single(greenChannel) - 0.5*(single(redChannel) + single(blueChannel))) > thresholdValue;
newRed = 255-greenChannel;
newRed(greenishPixels) = 255;
newGreen = 255-greenChannel;
newGreen(greenishPixels) = 0;
newBlue = 255-blueChannel;
newBlue(greenishPixels) = 0;
rgbImage2 = cat(3, newRed, newGreen, newBlue);
Related Question