ClassifyOnNN.m
上传用户:kandtrade
上传日期:2009-06-26
资源大小:12k
文件大小:2k
源码类别:

图形图象

开发平台:

Matlab

  1. %  ClassifyOnNN computes the classification accuracy
  2. %  CP=ClassifyOnNN(DM,trainClassIDs,testClassIDs) returns the classification accuracy 
  3. %  The input "DM" is a m*n distance matrix, m is the number of test samples, n is the number of training samples
  4. %  'trainClassIDs' and 'testClassIDs' stores the class ID of training and
  5. %  test samples
  6. %  Examples
  7. %  --------
  8. %       I1=imread('rice1.png');
  9. %       I2=imread('rice2.png');
  10. %       I3=imread('rice3.png');
  11. %       I4=imread('rice4.png');
  12. %       mapping=getmapping(8,'u2'); 
  13. %       M(1,:)=LBPV(I1,1,8,mapping); % LBPV histogram in (8,1) neighborhood using uniform patterns
  14. %       M(2,:)=LBPV(I2,1,8,mapping); 
  15. %       S(1,:)=LBPV(I3,1,8,mapping); 
  16. %       S(2,:)=LBPV(I4,1,8,mapping); 
  17. %       M = ConvertU2LBP(M,8); % convert u2 LBP or LBPV to meet the requirement of global matching scheme
  18. %       S = ConvertU2LBP(S,8);
  19. %       DM = distGMPDRN(M,S,8,2,3);
  20. %       CP=ClassifyOnNN(DM,[1,1],[1,1]);
  21. function CP=ClassifyOnNN(DM,trainClassIDs,testClassIDs)
  22. % Version 1.0
  23. % Authors: Zhenhua Guo, Lei Zhang and David Zhang
  24. % Copyright @ Biometrics Research Centre, the Hong Kong Polytechnic University
  25. if nargin<3
  26.     disp('Not enough input parameters.')
  27.     return
  28. end
  29. rightCount = 0;
  30. for i=1:length(testClassIDs);
  31.     [distNew, index]= min(DM(i,:));   % find Nearest Neighborhood
  32.     if trainClassIDs(index) == testClassIDs(i)  % judge whether the nearest one is correctly classified
  33.         rightCount = rightCount+1;
  34.     end
  35. end
  36. CP = rightCount/length(testClassIDs)*100;