read all images from subfolders
Afficher commentaires plus anciens
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?
Réponses (1)
Image Analyst
le 21 Mai 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 commentaires
fereshte
le 23 Mai 2014
Image Analyst
le 23 Mai 2014
Modifié(e) : Image Analyst
le 23 Mai 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
le 23 Mai 2014
Image Analyst
le 23 Mai 2014
use mkdir() to make a directory.
fereshte
le 23 Mai 2014
Image Analyst
le 23 Mai 2014
Make sure outputFolder has a value and is not empty.
Image Analyst
le 23 Mai 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
le 24 Mai 2014
Image Analyst
le 24 Mai 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
le 24 Mai 2014
Catégories
En savoir plus sur Image Preview and Device Configuration dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!