copying multiple images from one folder to other folder with conditions
12 次查看(过去 30 天)
显示 更早的评论
Dear Matlab Users
I have a folder with 14 pictures (C:\DT3\Pictures), i need to selected picture smaller than 512 x 512 pixel and copy it to SmallPicture.txt folder.
Thanks for the help!
0 个评论
采纳的回答
Walter Roberson
2021-8-29
编辑:Walter Roberson
2021-8-29
sourcefolder = 'C:\DT3\Pictures';
destfolder = 'C:\DT3\Pictures\SmallPicture';
if ~isfolder(destfolder); mkdir(destfolder); end
dinfo = dir(sourcefolder);
dinfo([dinfo.isdir]) = []; %remove subfolders and . and ..
filenames = fullfile({dinfo.folder}, {dinfo,name});
nfiles = length(filenames);
for K = 1 : nfiles
thisfile = filenames{K};
try
info = imfinfo(thisfile);
if ~isempty(info) && isfield(info, 'Width') && isfield(info,'Height') && info.Width <= 512 && info.Height <= 512
copyfile(thisfile, destfolder);
end
catch ME
%not an image, or headers not readable or copyfile failed
end
end
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!