DeepLearning: 数据预处理2:图片resize(matlab代码)

clear;close all;clc;
dir_path = '/home/li/lilai/myMatlabcode/code1/data';
position = strfind(dir_path,'/');
dir_path_new =[dir_path(1:position(end)),'data_new']

% mkdir(dir_path_new);
dir_list = dir(dir_path);
dir_list_num = length(dir_list);
for i = 3:dir_list_num
    dir_sub1_list = dir([dir_path,'/',dir_list(i).name]);
    dir_sub1_list_num = length(dir_sub1_list);
    for j = 3:dir_sub1_list_num
        dir_sub2_list = dir([dir_path,'/',dir_list(i).name,'/',dir_sub1_list(j).name]);
        dir_sub2_list_num = length(dir_sub2_list);
        mkdir([dir_path_new,'/',dir_list(i).name,'/',dir_sub1_list(j).name]);
        for k=3:dir_sub2_list_num
            img_path = [dir_path,'/',dir_list(i).name,'/',dir_sub1_list(j).name,'/',dir_sub2_list(k).name];
            img = imread(img_path);
            img_tmp = imresize(img,[32 32]);
            img_path_new = [dir_path_new,'/',dir_list(i).name,'/',dir_sub1_list(j).name,'/',dir_sub2_list(k).name,'.jpg'];
            imwrite(img_tmp,img_path_new)
        end
    end

end

你可能感兴趣的:(深度学习,matlab)