views:

410

answers:

1

Hello,

I have 500 images named Image1.tif all the way to Image500.tif and I need to convert all of them to grayscale and save them as Image1A.tif to Image500A.tif. Is there a quick way to do this? Thank you.

+6  A: 

If you have Image Processing Toolbox you can use RGB2GRAY function.

for k=1:500
    Ic=imread(['Image' num2str(k) '.tif']);
    Ig=rgb2gray(Ic);
    imwrite(Ig,['Image' num2str(k) 'A.tif'],'tif')
end

If you don't there is a solution here. Substitute rgb2gray line with:

Ig = 0.2989 * Ic(:,:,1) + 0.5870 * Ic(:,:,2) + 0.1140 * Ic(:,:,3); 
yuk