imageRootPath = '/n/fs/vision/datasets/SUN397/'; %% get image list disp('generating image list...'); folders = genpath(imageRootPath); folders = regexp(folders,':','split'); folders = folders(1:end-1); imageList = {}; for f=1:length(folders) imagefiles = dir(fullfile(folders{f},'*.jpg')); if ~isempty(imagefiles) for i=1:length(imagefiles) imageList{end+1} = fullfile(folders{f},imagefiles(i).name); end end end %% read image, crop, and resize disp('reading and resizing images...'); tWidth =32; tHeight=32; imArray = uint8(zeros(tHeight,tWidth,3,length(imageList))); for i=1:length(imageList) im = imread(imageList{i}); w = size(im,2); h = size(im,1); ch = w/tWidth*tHeight; if chh cw = h/tHeight*tWidth; if cw