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

图形图象

开发平台:

Matlab

  1. %  distGMES computes the dissimilarity between training samples and test
  2. %  samples by Exhaustive Searching Scheme of Global Matching
  3. %  DM = distGMES(trains, tests) returns the distance matrix between training samples and test samples. 
  4. %  The input "train" is a n*d matrix, and each row of it represents one
  5. %  training sample. The "test" is a m*d matrix.   
  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 = distGMES(M,S,8);
  20. function DM = distGMES(trains, tests,P)
  21. % Version 1.0
  22. % Authors: Zhenhua Guo, Lei Zhang and David Zhang
  23. % Copyright @ Biometrics Research Centre, the Hong Kong Polytechnic University
  24. if nargin<3
  25.     disp('Not enough input parameter')
  26.     return
  27. end
  28. % Get a group of permutation index for reorganizing the histogram to
  29. % simulate the rotation effect
  30. for i=1:P 
  31.     OrderIndex{i} = [(i-1)*(P-1)+1:P*(P-1)];
  32.     OrderIndex{i} = [OrderIndex{i},1:(i-1)*(P-1),P*(P-1)+1:P*(P-1)+3];
  33. end
  34. trainNum = size(trains,1);
  35. testNum = size(tests,1);
  36. DistMat = zeros(P,trainNum);
  37. DM = zeros(testNum,trainNum);
  38. for i=1:testNum;
  39.     test = tests(i,:);    
  40.     for k=1:P
  41.         DistMat(k,:) = distMATChiSquare(trains,test(OrderIndex{k}))';
  42.     end
  43.     DM(i,:) = min(DistMat);
  44. end