将RGB图像转换为灰度图像并使用Matlab重命名 [英] Converting rgb images to grayscale and renaming them using matlab

查看:115
本文介绍了将RGB图像转换为灰度图像并使用Matlab重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有500幅名为Image1.tif的图像一直到Image500.tif,我需要将它们全部转换为灰度并将它们另存为Image1A.tif到Image500A.tif.有没有一种快速的方法可以做到这一点?谢谢.

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.

推荐答案

如果您拥有图像处理工具箱,则可以使用RGB2GRAY功能.

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

这篇关于将RGB图像转换为灰度图像并使用Matlab重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆