matlab-bmp2jpg
%% 将文件夹LFW_align_man5pt下的5K多个子文件夹下的.bmp图片转换为.jpg close all; clear; clc; maindir = 'F:\dataset\LFW_align_man5pt\'; subdir = dir( maindir ); % 先确定子文件夹 disp('共有:'),disp(length(subdir)); total_num=1; for i = 3 : length( subdir ) if( isequal( subdir( i ).name, '.' ) || ... isequal( subdir( i ).name, '..' )) continue; end path1 = fullfile(maindir,subdir( i ).name,'\'); % disp(subdir( i ).name) % 接下来是新建子文件夹 if ~exist(['F:\dataset\LFW_align_jpg\',subdir(i).name],'dir') mkdir(['F:\dataset\LFW_align_jpg\',subdir(i).name]); end path2= dir(path1);%获取该文件夹中所有bmp格式的图像 % disp (path2) for j=1:length( path2 ) if( isequal( path2( j ).name, '.' ) || ... isequal( path2( j ).name, '..' )|| ... isequal( path2( j ).name, 'Thumbs.db' )) continue; end % disp(path2(j).name) imgname = path2(j).name(1:(end-4)) % disp(imgname) path=fullfile( maindir, subdir( i ).name,'\',path2(j).name); % disp (path) img = imread( path ); % 这里进行你的读取操作 filename = strcat(imgname,'.jpg'); imwrite(img,['F:\dataset\LFW_align_jpg\',subdir(i).name,'\',filename]); end end