问题
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.
回答1:
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);
来源:https://stackoverflow.com/questions/2348037/converting-rgb-images-to-grayscale-and-renaming-them-using-matlab