How to read multiple images from a folder which have sub-folders ? matlab code

Sir/madam, I need ur help in Matlab "How to read multiple images from a folder which have sub-folders ? " Like I have a database which hv a folder with name "faces94" n it hv further 40 subfolders and each folder hv 5 images in it so plz help me how to read them in matlab n than save them n show them too plz help me with matlab code i'm too bad in logic plz
Regards Farhan Aslam

 Accepted Answer

See attached recursion demo to recurse into each subfolder getting filenames.

9 Comments

Farhan said in another "Answer":
thank you sir(Image Analyst ) for ur answer and plz tell me how to show the image in it i mean like we read an image using IMREAD n then show it using IMSHOW so how will this thing work in ur code :)
So just put an imread() and imshow() after you get the filename, like this:
% Start with a folder and get a list of all subfolders.
% Finds and prints names of all PNG, JPG, and TIF images in
% that folder and all of its subfolders.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
% Define a starting folder.
start_path = fullfile(matlabroot, '\toolbox\images\imdemos');
% Ask user to confirm or change.
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
% Get list of all subfolders.
allSubFolders = genpath(topLevelFolder);
% Parse into a cell array.
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
numberOfFolders = length(listOfFolderNames)
% Process all image files in those folders.
for k = 1 : numberOfFolders
% Get this folder and print it out.
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
% Get PNG files.
filePattern = sprintf('%s/*.png', thisFolder);
baseFileNames = dir(filePattern);
% Add on TIF files.
filePattern = sprintf('%s/*.tif', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
% Add on JPG files.
filePattern = sprintf('%s/*.jpg', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
numberOfImageFiles = length(baseFileNames);
% Now we have a list of all files in this folder.
if numberOfImageFiles >= 1
% Go through all those image files.
for f = 1 : numberOfImageFiles
fullFileName = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing image file %s\n', fullFileName);
theImage = imread(fullFileName);
imshow(theImage);
axis on;
promptMessage = sprintf('Do you want to Continue processing,\nor Cancel to abort processing?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
end
else
fprintf(' Folder %s has no image files in it.\n', thisFolder);
end
end
Hello, The images of CASIA-IrisV1 are stored as: $root path$/XXX_S_Y.bmp XXX: the unique identifier of eye, range from 000 to 108. S: the index of session, denotes the first session and the second session. Y: the index of image in the same session. Range from 1 to 3 in the first session, 1 to 4 in the second session. Therefore XXX_S_Y:bmp means the iris image with index Y in session S from eye XXX. XXX=000:108 (t0tally 108 folders) And if S=1,THEN Y=1:3 (1st sub-folder i.e if S=1, then it contains 3 images If S=2, Then Y=1:4 (2nd Sub-folder i.e if S=2, then it contains 4 images).. so for a folder there will be 7 images(3 images in 1st subfolder and 4 images in 2nd subfolder)... Totally 108 folders..so there will be 108 * 7= 756 images from the database.. i want load all those images and store in a cell array... I am sending you zip code with some images..
I do not see any reason to store the entire collection of images in memory simultaneously when you process them one at a time. Why? You may not even have memory to do that. If every image is a 30 MB image then you'd need almost 3 GB of free RAM. Again, why ?
actually i want to use libormasek code...now in that code, i need to pass an image in createiristemplate.m file...How can i pass each image from the database to createiristemplete.m file...i want to process all the images from the database in an order using natsortfiles.m...can you please help me.
here is the code for createiristemplate...now in the function,the parameter eyeimage_filename is the image from the database....so,this file must run for all the images in the database and the result must be stored in an array or matrix for further process
% createiristemplate - generates a biometric template from an iris in
% an eye image.
%
% Usage:
% [template, mask] = createiristemplate(eyeimage_filename)
%
% Arguments:
% eyeimage_filename - the file name of the eye image
%
% Output:
% template - the binary iris biometric template
% mask - the binary iris noise mask
%
% Author:
% Libor Masek
% masekl01@csse.uwa.edu.au
% School of Computer Science & Software Engineering
% The University of Western Australia
% November 2003
function [template, mask] = createiristemplate(eyeimage_filename)
% path for writing diagnostic images
global DIAGPATH
DIAGPATH = 'C:\Users\admin\Desktop\diagnostics/';
%normalisation parameters
radial_res = 20;
angular_res = 240;
% with these settings a 9600 bit iris template is
% created
%feature encoding parameters
nscales=1;
minWaveLength=18;
mult=1; % not applicable if using nscales = 1
sigmaOnf=0.5;
eyeimage = imread(eyeimage_filename);
savefile = [eyeimage_filename,'-houghpara.mat'];
[stat,mess]=fileattrib(savefile);
if stat == 1
% if this file has been processed before
% then load the circle parameters and
% noise information for that file.
load(savefile);
else
% if this file has not been processed before
% then perform automatic segmentation and
% save the results to a file
[circleiris circlepupil imagewithnoise] = segmentiris(eyeimage);
save(savefile,'circleiris','circlepupil','imagewithnoise');
end
% WRITE NOISE IMAGE
%
imagewithnoise2 = uint8(imagewithnoise);
imagewithcircles = uint8(eyeimage);
%get pixel coords for circle around iris
[x,y] = circlecoords([circleiris(2),circleiris(1)],circleiris(3),size(eyeimage));
ind2 = sub2ind(size(eyeimage),double(y),double(x));
%get pixel coords for circle around pupil
[xp,yp] = circlecoords([circlepupil(2),circlepupil(1)],circlepupil(3),size(eyeimage));
ind1 = sub2ind(size(eyeimage),double(yp),double(xp));
% Write noise regions
imagewithnoise2(ind2) = 255;
imagewithnoise2(ind1) = 255;
% Write circles overlayed
imagewithcircles(ind2) = 255;
imagewithcircles(ind1) = 255;
w = cd;
cd(DIAGPATH);
imwrite(imagewithnoise2,[eyeimage_filename,'-noise.jpg'],'jpg');
imwrite(imagewithcircles,[eyeimage_filename,'-segmented.jpg'],'jpg');
cd(w);
% perform normalisation
[polar_array noise_array] = normaliseiris(imagewithnoise, circleiris(2),...
circleiris(1), circleiris(3), circlepupil(2), circlepupil(1), circlepupil(3),eyeimage_filename, radial_res, angular_res);
% WRITE NORMALISED PATTERN, AND NOISE PATTERN
w = cd;
cd(DIAGPATH);
imwrite(polar_array,[eyeimage_filename,'-polar.jpg'],'jpg');
imwrite(noise_array,[eyeimage_filename,'-polarnoise.jpg'],'jpg');
cd(w);
% perform feature encoding
[template mask] = encode(polar_array, noise_array, nscales, minWaveLength, mult, sigmaOnf);
Hello! How can sift be performed on the images in the array in the code above
It is not obvious to me that there are images in an array in that code?

Sign in to comment.

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!