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?

Answers (1)

Image Analyst
Image Analyst on 21 May 2014
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

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?
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
thanks but i get this error:
??? Undefined function or method 'mkrid' for input arguments of type 'char'.
Error in ==> pixel at 11 mkrid(outputFolder);
use mkdir() to make a directory.
??? Error using ==> mkdir Not enough input arguments.
Error in ==> resize at 11 mkdir();
how correct it?
Make sure outputFolder has a value and is not empty.
fereshte
fereshte on 23 May 2014
Edited: fereshte on 23 May 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\';
i have this line in my code.i dont know why empty
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.
ok.thanks a lot

Sign in to comment.

Categories

Asked:

on 21 May 2014

Commented:

on 24 May 2014

Community Treasure Hunt

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

Start Hunting!