read all images from subfolders
Show older comments
hi.i have a folder with subfolders that each folder contains ten folder and these folders have 4 image files. how can resize all images with matlab code?
Answers (1)
Image Analyst
on 21 May 2014
0 votes
Combine the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F with imresize() and you can do it. Create two filenames with sprintf() and fullfile(). Call imread() then imresize() then imwrite(). If you cannot do that, then post your code for us to fix.
12 Comments
fereshte
on 23 May 2014
Image Analyst
on 23 May 2014
Edited: Image Analyst
on 23 May 2014
Try this:
inputFolder = 'C:\Users\Zare\Downloads\Compressed\Gait and Footprint\Footprint';
if ~exist(inputFolder, 'dir')
errorMessage = sprintf('Error: The following folder does not exist:\n%s', inputFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(inputFolder, '*.bmp');
bmpFiles = dir(filePattern);
outputFolder = 'C:\Users\Zare\Downloads\Compressed\Gait and Footprint\Footprint\resized\';
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
end
for k = 1:numel(bmpFiles)
fullInputFileName = fullfile(inputFolder, bmpFiles(k).name);
originalImage = imread(fullInputFileName);
fullOutputFileName = fullfile(outputFolder, bmpFiles(k).name);
outputImage = imresize(originalImage, [100,50]);
imwrite(outputImage, fullOutputFileName);
end
fereshte
on 23 May 2014
Image Analyst
on 23 May 2014
use mkdir() to make a directory.
fereshte
on 23 May 2014
Image Analyst
on 23 May 2014
Make sure outputFolder has a value and is not empty.
Image Analyst
on 23 May 2014
And why is it empty? Did you not have this line in there like I did:
outputFolder = 'C:\Users\Zare\Downloads\Compressed\Gait and Footprint\Footprint\resized\';
fereshte
on 24 May 2014
Image Analyst
on 24 May 2014
Well figure it out. Step through one line at a time until you see the value of it vanish. See http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
In the meantime, I attach a program to recurse into subfolders getting image names.
fereshte
on 24 May 2014
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!