MATLAB: 指定路径下图片批量化处理并保存到另一路径

功能:读取某一路径下全部png文件,批量处理后再按原文件名保存到另一路径下

参考链接:https://www.computationalimaging.cn/2020/01/matlab-batch-process-pictures-under.html

file_path =  './seeprettyface_models/';
img_path_list = dir(strcat(file_path,'*.png'));
dist_path = './chaomo/';


filePathTry = 'G:\Face\B_try\B_try';
filePathBtest = 'G:\Face\B_try\B\test';
filePathBtrain = 'G:\Face\B_try\B\train';
filePathBval = 'G:\Face\B_try\B\val';
filePathAtest = 'G:\Face\B_try\A\test';
filePathAtrain = 'G:\Face\B_try\A\train';
filePathAval = 'G:\Face\B_try\A\val';

h = waitbar(0,'Moving..., please wait');
% train
for im =1:length(img_path_list)
    fileName = img_path_list(im).name;
    filePath =  img_path_list(im).folder;
    fileImage = strcat(filePath,'\',fileName);
    distImage = strcat(dist_path,'\',fileName);
    image = imread(fileImage);
    image = imresize(image,[256,256]);
    imwrite(image,distImage);
    str = ['Moving image...',num2str(im*100/length(img_path_list)),'%'];
    waitbar(im/length(img_path_list),h,str)
end
发布了47 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qazwsxrx/article/details/103703270