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

2 次查看(过去 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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by