MATLAB批量将单通道图片转换为三通道图片

           在做深度学习训练模型时需要输入为三通道图片,当获得的数据集为单通道图片时,就需要将其转换为三通道图片。
 pathdir = 'E:/Image_Set/HYAL/';%文件路径
format = 'bmp';%文件格式
files = dir(strcat(pathdir,'*.',format));
% dir 列出当前文件夹中的文件和文件夹。
% strcat 水平串联字符串
%    列出文件夹中后缀为.bmp的文件
steps = 100;
hwait = waitbar(0,'准备开始');
for n = 1:numel(files)
    filename = strcat(pathdir,files(n).name);
    img = imread(filename);
    x = repmat(img,[1,1,3]);%将单通道图片转换为三通道图片
    imwrite(x,filename,'bmp');
    str = '正在运行中....';
    waitbar(n/numel(files),hwait,str)
end
close(hwait);

猜你喜欢

转载自blog.csdn.net/qq_41569159/article/details/89048693
今日推荐