Saturday, November 13, 2010

How do you change red pixels into green pixels in Matlab?

I have a RGB image and I need to turn all the red pixels into green pixels. How do I do this??

Please and thank you!!!!How do you change red pixels into green pixels in Matlab?
clear all;clc

%Create a colour image

r=repmat([1:1:255],255,1);

g=fliplr(repmat([1:1:255],255,1));

b=ones(255,255);

M(:,:,1)=r;

M(:,:,2)=g;

M(:,:,3)=b;

M=uint8(M);



%Write the image to file

imwrite(M,'im.bmp')



%Display the image

figure(1);image(M);title('original image')



%Load the image from file

M2=imread('im.bmp');

r=M2(:,:,1);

g=M2(:,:,2);

b=M2(:,:,3);



%flip the colour channels

M(:,:,1)=g;

M(:,:,2)=r;

M(:,:,3)=b;



%display the image

figure(2);image(M);title('swap colour channels')

No comments:

Post a Comment