读取多个子文件夹内的全部图片

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值