Matlab code to select some images from numbers of images and assign them as training set

조회 수: 3 (최근 30일)
I have an image database which consist of 40 folders and in each folder, there are 6 images of individuals. The total images are now 240 images. Now in each folder, i want to select two images, i.e image no 3 and no 4 and assign them as testing set while the remaining four will be assign as training set. This should happen for all the images in the folders in the database at once. How do i do the matlab coding. I need help.

답변 (1개)

Jakob B. Nielsen
Jakob B. Nielsen 2019년 12월 10일
First, you want to name your folders in a consistent manner so you can easily make matlab count it. Then something like:
foldername='C:\Databasefolder\Folder1'
for i=1:40
%Put your code to assign images from Folder1 here
foldername=strrep(foldername,strcat('Folder',num2str(i)),strcat('Folder',num2str(i+1)));
%That bit will change the foldername to Folder2, and the next time, to Folder3.
end
  댓글 수: 1
Abdulmu'min Musa
Abdulmu'min Musa 2019년 12월 11일
편집: Abdulmu'min Musa 2019년 12월 11일
I tried that code above but it didnt work. This is how my initial code is;
%Load Image
faceDatabase = imageSet('T8ATT','recursive');
%Display Query Image and Database side by side
fprintf('Press Enter to select image')
pause;
[filename,pathname]=uigetfile({'*.jpg'},'Pick an image file');
galleryImage=imread([pathname,filename]);
figure;
for i=1:size(faceDatabase,2)
imageList(i)=faceDatabase(i).ImageLocation(1);
end
subplot(1,2,1);imshow(galleryImage);title('Selected Image');
subplot(1,2,2);montage(imageList);title('Database Image');
pause(0.002)
% diff=zeros(1,5);
%Split Database into Training and Test sets
[training,test]=partition(faceDatabase,[0.6 0.4]);
%Extract and display Histogram of Oriented Gradient (HOG) features for
%single face
[hogFeature,visualization]=......
extractHOGFeatures(galleryImage);
% figure;
% subplot(2,1,1);imshow(galleryImage);title('Input face');
% subplot(2,1,2);plot(visualization);title('HOG Feature');
figure;
imshow(galleryImage);title('Input face');
figure;
plot(visualization);title('HOG Feature');
%Extract HOG Features for Training Set
trainingFeatures=[];
featureCount=1;
for i=1:size(training,2)
for j=1:training(i).Count
trainingFeatures(featureCount,:)=extractHOGFeatures(read(training(i),j));
trainingLabel{featureCount}=training(i).Description;
featureCount=featureCount+1;
end
personIndex{i}=training(i).Description;
end
% Create 40 class classifier using fitcecoc
faceClassifier=fitcecoc(trainingFeatures,trainingLabel);
%Test Images from Test Set
queryFeatures = extractHOGFeatures(galleryImage);
personLabel=predict(faceClassifier,que
Using this my code, i can partition all the image folder into 2 with this code
%Split Database into Training and Test sets
[training,test]=partition(faceDatabase,[0.6 0.4]);
This partition the image folder into first 4 images for "training" and last 2 images for "testing".
Now, i want to get a code where i can assign the image number 3 and 4 as "Test" and the rest as "Training" or image number number 2 and 4 as "Test" and the rest as "Training".
Help.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by