read all images from subfolders

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
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
fereshte le 22 Mai 2014
Modifié(e) : fereshte le 22 Mai 2014
my code is:
clear all;
close all;
clc;
myFolder = 'C:\Users\Zare\Downloads\Compressed\Gait and Footprint\Footprint';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.bmp');
bmpFiles = dir(filePattern);
for k = 1:numel(bmpFiles)
A = imread(bmpFiles(k).name);
A3=imresize(A,[100,50]);
imwrite(A3,['C:\Users\Zare\Downloads\Compressed\Gait and Footprint\Footprint\Cropped\'bmpFiles(k).name],'bmp');
end
error is:
??? Error: File: resize.m Line: 16 Column: 87 Unexpected MATLAB expression.
dear Image Analyst
can you help me?
Image Analyst
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
fereshte le 23 Mai 2014
thanks but i get this error:
??? Undefined function or method 'mkrid' for input arguments of type 'char'.
Error in ==> pixel at 11 mkrid(outputFolder);
Image Analyst
Image Analyst le 23 Mai 2014
use mkdir() to make a directory.
fereshte
fereshte le 23 Mai 2014
??? Error using ==> mkdir Not enough input arguments.
Error in ==> resize at 11 mkdir();
how correct it?
Image Analyst
Image Analyst le 23 Mai 2014
Make sure outputFolder has a value and is not empty.
fereshte
fereshte le 23 Mai 2014
Modifié(e) : fereshte le 23 Mai 2014
outputFolder is empty
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
fereshte le 24 Mai 2014
i have this line in my code.i dont know why empty
Image Analyst
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
fereshte le 24 Mai 2014
ok.thanks a lot

Connectez-vous pour commenter.

Question posée :

le 21 Mai 2014

Commenté :

le 24 Mai 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by