clc;
clear all;
maindir = '图片路径';
subdir = dir( maindir ); % 先确定子文件夹
for i = 1 : length( subdir )
if( isequal( subdir( i ).name, '.' ) || ...
isequal( subdir( i ).name, '..' ) || ...
~subdir( i ).isdir ) % 如果不是目录跳过
continue;
end
subdirpath = fullfile( maindir, subdir( i ).name, '*.png' );
images = dir( subdirpath ); % 在这个子文件夹下找后缀为jpg的文件
% 遍历每张图片
for j = 1 : length( images )
imagepath = fullfile( maindir, subdir( i ).name, images( j ).name );
imgdata = imread( imagepath ); % 这里进行你的读取操作
imwrite(imgdata,['存储路径\',num2str(i),'-',num2str(j),'.png']);
end
end
读取多个子文件夹内的全部图片
最新推荐文章于 2024-07-28 20:37:54 发布