在SVM分类器中测试/匹配图像

时间:2016-03-13 16:23:04

标签: matlab svm

我从一组20images中提取了HoG特征。我使用以下代码进行了分类...但是我在测试分类器时遇到了问题。你做错了什么,请帮忙...

 %% Load Images
 imgFolder1 = fullfile('C:\Users\Engineering\Desktop\Finn\NEW');
  imgFolder2 = fullfile('C:\Users\Engineering\Desktop\Finn\NEW2');

  training = imageSet(imgFolder1);
  test = imageSet(imgFolder2);

 %% Extract and display Histogram of Oriented Gradient Features for single Note 
[hogFeature, visualization]= ...
       extractHOGFeatures(read(training,1));
 figure;
 subplot(2,1,1);imshow(read(training,1));title('Input Face');
 subplot(2,1,2);plot(visualization);title('HoG Feature');

 %% Extract HOG Features for training set 
trainingFeatures = [];
trainingLabel = [];

for i =  1:training.Count
[hogFeature, visualization] = ...
         extractHOGFeatures(read(training,i));
trainingFeatures = [trainingFeatures;hogFeature];

  end

%%     
labels = repmat(training.Description, i);

trainingLabel   = [trainingLabel;   labels];

%%我不确定noteIndex的这一行:

   noteIndex = trainingLabel, i

 %% Create 20 class classifier using fitcecoc 

 noteClassifier = fitcecoc(trainingFeatures,trainingLabel);


 %% Test Images from Test Set 
 note = 1;
 queryImage = read(test(note),1);
 queryFeatures = extractHOGFeatures(queryImage);
 noteLabel = predict(noteClassifier,queryFeatures);

 % Map back to training set to find identity 
 booleanIndex = strcmp(noteLabel, noteIndex);
 integerIndex = find(booleanIndex);
  subplot(1,2,1);imshow(queryImage);title('Query Face');
  subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched Class');

 %% Test First 5 notes from Test Set
 figure;
 figureNum = 1;
 for note=1
for k = 1:test(note).Count
    queryImage = read(test(note),k);
    queryFeatures = extractHOGFeatures(queryImage);

    noteLabel = predict(noteClassifier,queryFeatures);

    % Map back to training set to find identity
    booleanIndex = strcmp(noteLabel, noteIndex);
    integerIndex = find(booleanIndex);
          subplot(4,4,figureNum);imshow(imresize(queryImage,3));title('Query Note');
          subplot(4,4,figureNum+1);imshow(imresize(read(training(integerIndex),1),3));title('Matched Class');
    figureNum = figureNum+2;

end
figure;
figureNum = 1;

%% I get these errors: 
 (this method is not supported for arrays if image Set objects.) 

 %%And 
 (error in: subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched Class');

%% so it displays query image but match image is like a graph plot with no image.

0 个答案:

没有答案