RGB彩色图像批量转为单通道灰度图(matlab)

RGB图像转为单通道灰度图像,修改文件夹中指定格式所有图片文件


pathdir='D:/image/';%文件夹路径
format = 'png';%文件格式
files=dir(strcat(pathdir,'*.',format));
steps=100;
hwait=waitbar(0,'准备开始');
for n=1:numel(files)
     filename=strcat(pathdir,files(n).name);
     img=imread(filename);
     x=rgb2gray(img);
     imwrite(x,filename,'png');%自动设置为替换原文件,可以修改
     str='正在运行中巴啦啦巴啦';
     waitbar(n/numel(files),hwait,str);
end
close(hwait);

加入了进度条,方便查看进度。



猜你喜欢

转载自blog.csdn.net/x_cosmic/article/details/79971003