how can i read/train all images from subfolders
이전 댓글 표시
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
채택된 답변
추가 답변 (3개)
Dima Lisin
2015년 1월 12일
0 개 추천
If you have a recent version of MATLAB with the Computer Vision System Toolbox, then you can use imageSet.
댓글 수: 2
mark
2015년 1월 12일
Dima Lisin
2015년 1월 13일
편집: Dima Lisin
2015년 1월 13일
imgSets = imageSet('.\database\', 'recursive');
will return an array of imageSet objects.
imgSets(1).Description
will contain the name of the first subfolder.
imshow(read(imgSets(2), 2));
will display the second image in the second folder. Please see the documentation of imageSet for more details.
Priyabrata Karmakar
2016년 2월 3일
You can use the following code. Cut and paste the whole code from below, insert the path of your main database folder in 'Database Path' section. sourceFiles consists of the paths of individual images which you can read using imread function.[imread(sourceFiles(i).name]. labels which is needed during classification will give you the corresponding labels of individuals images in sourceFiles.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
imgSets = imageSet('Database Path', 'recursive'); m=1;sourceFiles=[];labels=[]; for i=1:length(imgSets) srcFiles=dir(strcat('Database Path\',imgSets(i).Description,'\*.jpg'));
for j=1:length(srcFiles)
srcFiles(j).name = strcat('Database Path\',imgSets(i).Description,'\',srcFiles(j).name);
end
l=length(srcFiles);
label=m*ones(l,1);
sourceFiles=[sourceFiles;srcFiles];
labels=[labels;label];
m=m+1;
end
aras masood
2017년 1월 28일
0 개 추천
hello every on please anyone tell me i have a database for hand recognition i want replace this database to a folder which is consists of a set of images i want use them to train and recognize faces by this folder could anyone tell me how to do such things please ?
댓글 수: 1
Walter Roberson
2017년 1월 28일
We need further information about what is stored in the database and how the program accesses the data. For example the database might contain the weights of a trained neural network that has already been trained on extracted features and so it might be necessary to do a bunch of computing on your custom images. We do not know, as you do not give enough information.
But instead of replying here you should open a new Question for this and give the details there and then delete this post.
카테고리
도움말 센터 및 File Exchange에서 Computer Vision Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!