1 function ResizeImageofData
2 % 读取文件夹下的所有数据
3 Files = dir('D:\1\'); %父文件夹
4 LengthFiles = length(Files);
5 oldFolder = cd; %打开当前工作目录
6 spath=strcat(oldFolder,'\Data\'); % 在工程目录下创建名为'\Data\'的新文件夹
7
8 if ~exist(spath,'dir')
9 mkdir(spath)
10 end
11
12 for i = 3:LengthFiles
13 ChildFile = dir(strcat('D:\1\',Files(i,1).name,'\*.*'));
14 N = length(ChildFile);
15 for j = 3:1:N
16 Img = imread(strcat('D:\1\',Files(i,1).name,'\',ChildFile(j).name));
17 if ndims(Img)>2
18 if ndims(Img)==3
19 Img=rgb2gray(uint8(Img));
20 else
21 return;
22 end
23 end
24 Img= imresize(Img,[800,600]);
25 imwrite(Img, strcat(spath,Files(i).name,'_', ChildFile(j).name));
26 end
27 end