Converting rgb images to grayscale and renaming them using matlab

随声附和 提交于 2019-12-24 02:25:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!