MATLAB: How can i read/train all images from subfolders

Computer Vision Toolboxstructures

hello can you help me to modified my code? so i have 3 subfolder in database folder and every subfolder there is 5 pictures on it and i want to read all images in all subfolders and train it.
this is my code that i use in training all images from database folder:
clc;
dn='.\database\';
db=dir(strcat(dn,'*.jpg'));
k=1;
%length(db)
p=1;
for(i=1:1:length(db))
fname=db(i).name;
fname=strcat(dn,fname);
im=imread(fname);
axes(handles.axes1);
imshow(im);
im=rgb2gray(im);
im=imresize(im,[256 256]);
X=double(im);
k=k+1;
f=lbp_sir(X);
plot(f);
Features(:,p)=f;
TrnFile(p).name=fname;
p=p+1;
end;
save features Features TrnFile

Best Answer

See my attached demo that will recurse into all subfolders and get image file names. Then process them in whatever way you want.