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);