emd.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef _EMD_H
  2. #define _EMD_H
  3. /*
  4. emd.h
  5. Last update: 3/24/98
  6. An implementation of the Earth Movers Distance.
  7. Based of the solution for the Transportation problem as described in
  8. "Introduction to Mathematical Programming" by F. S. Hillier and
  9. G. J. Lieberman, McGraw-Hill, 1990.
  10. Copyright (C) 1998 Yossi Rubner
  11. Computer Science Department, Stanford University
  12. E-Mail: rubner@cs.stanford.edu URL: http://vision.stanford.edu/~rubner
  13. */
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /* DEFINITIONS */
  18. #define MAX_SIG_SIZE 100
  19. #define MAX_ITERATIONS 5000
  20. #undef INFINITY
  21. #define INFINITY 1e20
  22. #define EPSILON 1e-6
  23. /*****************************************************************************/
  24. /* feature_t SHOULD BE MODIFIED BY THE USER TO REFLECT THE FEATURE TYPE */
  25. typedef double* feature_t;
  26. /*****************************************************************************/
  27. typedef struct
  28. {
  29. int n; /* Number of features in the signature */
  30. // refactor-nice.pl: check this substitution
  31. // old: feature_t *Features; /* Pointer to the features vector */
  32. feature_t *Features; /* Pointer to the features std::vector */
  33. float *Weights; /* Pointer to the weights of the features */
  34. } signature_t;
  35. typedef struct
  36. {
  37. int from; /* Feature number in signature 1 */
  38. int to; /* Feature number in signature 2 */
  39. float amount; /* Amount of flow from "from" to "to" */
  40. } flow_t;
  41. float emd(signature_t *Signature1, signature_t *Signature2,
  42. float (*func)(feature_t *, feature_t *),
  43. flow_t *Flow, int *FlowSize);
  44. #ifdef __cplusplus
  45. } /* extern C */
  46. #endif
  47. #endif