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

图形图象

开发平台:

Matlab

  1. %  distMATChiSquare computes the dissimilarity between training samples and a test sample
  2. %  DV = distMATChiSquare(train, test) returns the distance vector between training samples and a test sample. 
  3. %  The input "train" is a n*d matrix, and each row of it represent one
  4. %  training sample. The "test" is a 1*d vector.   
  5. %  Examples
  6. %  --------
  7. %       I1=imread('rice1.png');
  8. %       I2=imread('rice2.png');
  9. %       I3=imread('rice3.png');
  10. %       mapping=getmapping(8,'u2'); 
  11. %       M(1,:)=LBPV(I1,1,8,mapping); % LBPV histogram in (8,1) neighborhood using uniform patterns
  12. %       M(2,:)=LBPV(I2,1,8,mapping); 
  13. %       S=LBPV(I3,1,8,mapping); 
  14. %       DV = distMATChiSquare(M,S);
  15. function DV = distMATChiSquare(trains, test)
  16. % Version 1.0
  17. % Authors: Zhenhua Guo, Lei Zhang and David Zhang
  18. % Copyright @ Biometrics Research Centre, the Hong Kong Polytechnic University
  19. [train_row, train_col] = size(trains);
  20. [test_row, test_col] = size(test);
  21. testExtend = repmat(test, train_row, 1);
  22. subMatrix = trains-testExtend;
  23. subMatrix2 = subMatrix.^2;
  24. addMatrix = trains+testExtend;
  25. idxZero = find(addMatrix==0);
  26. addMatrix(idxZero)=1;
  27. DistMat = subMatrix2./addMatrix;
  28. DV = sum(DistMat,2);