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 发布
本文介绍了一个使用Matlab编写的脚本,该脚本能够遍历指定目录及其子目录下的所有PNG图片,对其进行读取,并将处理后的图片保存到设定的存储路径。这个过程包括了对每个子目录中图片的遍历和读取操作。
6103

被折叠的 条评论
为什么被折叠?



