FCGreyValues.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file FCGreyValues.cpp
  3. * @brief extract simple greyvalue features
  4. * @author Erik Rodner
  5. * @date 11/15/2007
  6. */
  7. #include <iostream>
  8. #include "vislearning/features/simplefeatures/FCGreyValues.h"
  9. using namespace OBJREC;
  10. using namespace std;
  11. // refactor-nice.pl: check this substitution
  12. // old: using namespace ice;
  13. using namespace NICE;
  14. FCGreyValues::FCGreyValues( const Config * conf, int _xsize, int _ysize ) :
  15. FeatureFactory ( conf ), xsize(_xsize), ysize(_ysize)
  16. {
  17. xsize = conf->gI("FCGreyValues", "xsize", _xsize <= 0 ? 20 : _xsize );
  18. ysize = conf->gI("FCGreyValues", "ysize", _ysize <= 0 ? 50 : _ysize );
  19. // refactor-nice.pl: check this substitution
  20. // old: string normalization_s = conf->gS("FCGreyValues", "normalization", "n01");
  21. std::string normalization_s = conf->gS("FCGreyValues", "normalization", "n01");
  22. if ( normalization_s == "n01" )
  23. normalization = NORMALIZE_N01;
  24. else if ( normalization_s == "stddev" )
  25. normalization = NORMALIZE_STDDEV;
  26. else if ( normalization_s == "mean" )
  27. normalization = NORMALIZE_MEAN;
  28. else if ( normalization_s == "none" )
  29. normalization = NORMALIZE_NONE;
  30. else {
  31. fprintf (stderr, "FCGreyValues::FCGreyValues: unknown normalization method\n");
  32. exit(-1);
  33. }
  34. // refactor-nice.pl: check this substitution
  35. // old: tmp = NewImg(xsize, ysize, 255);
  36. tmp.resize(xsize, ysize);
  37. }
  38. FCGreyValues::~FCGreyValues()
  39. {
  40. }
  41. // refactor-nice.pl: check this substitution
  42. // old: int FCGreyValues::convert ( const Image & img, Vector & vec )
  43. int FCGreyValues::convert ( const NICE::Image & img, NICE::Vector & vec )
  44. {
  45. tmp.set(0);
  46. NICE::scale ( img, &tmp );
  47. vec.resize(xsize*ysize);
  48. double mean = 0.0;
  49. double stddev = 0.0;
  50. if ( normalization != NORMALIZE_NONE )
  51. {
  52. // compute mean
  53. for ( int yi = 0 ; yi < ysize ; yi++ )
  54. for ( int xi = 0 ; xi < xsize ; xi++ )
  55. // refactor-nice.pl: check this substitution
  56. // old: mean += GetVal(tmp, xi, yi);
  57. mean += tmp.getPixel(xi,yi);
  58. mean /= (xsize*ysize);
  59. if ( normalization != NORMALIZE_MEAN )
  60. {
  61. // compute stddev
  62. stddev = 0.0;
  63. for ( int yi = 0 ; yi < ysize ; yi++ )
  64. for ( int xi = 0 ; xi < xsize ; xi++ )
  65. {
  66. // refactor-nice.pl: check this substitution
  67. // old: double d = GetVal(tmp,xi,yi) - mean;
  68. double d = tmp.getPixel(xi,yi) - mean;
  69. stddev += d*d;
  70. }
  71. if ( stddev < 10e-5 ) return -1;
  72. stddev /= xsize*ysize;
  73. stddev = sqrt(stddev);
  74. }
  75. }
  76. if ( normalization == NORMALIZE_STDDEV )
  77. {
  78. // normalize pixel values
  79. int k = 0;
  80. for ( int yi = 0; yi < ysize ; yi++ )
  81. for ( int xi = 0; xi < xsize ; xi++,k++ )
  82. // refactor-nice.pl: check this substitution
  83. // old: vec[k] = (GetVal(tmp,xi,yi) - mean) / stddev + mean;
  84. vec[k] = (tmp.getPixel(xi,yi) - mean) / stddev + mean;
  85. } else if ( normalization == NORMALIZE_N01 ) {
  86. // normalize pixel values
  87. int k = 0;
  88. for ( int yi = 0 ; yi < ysize ; yi++ )
  89. for ( int xi = 0 ; xi < xsize ; xi++,k++ )
  90. // refactor-nice.pl: check this substitution
  91. // old: vec[k] = (GetVal(tmp,xi,yi) - mean) / stddev;
  92. vec[k] = (tmp.getPixel(xi,yi) - mean) / stddev;
  93. } else if ( normalization == NORMALIZE_MEAN ) {
  94. // normalize pixel values
  95. int k = 0;
  96. for ( int yi = 0 ; yi < ysize ; yi++ )
  97. for ( int xi = 0 ; xi < xsize ; xi++,k++ )
  98. // refactor-nice.pl: check this substitution
  99. // old: vec[k] = (GetVal(tmp,xi,yi) - mean);
  100. vec[k] = (tmp.getPixel(xi,yi) - mean);
  101. } else {
  102. int k = 0;
  103. for ( int yi = 0 ; yi < ysize ; yi++ )
  104. for ( int xi = 0 ; xi < xsize ; xi++,k++ )
  105. // refactor-nice.pl: check this substitution
  106. // old: vec[k] = GetVal(tmp,xi,yi);
  107. vec[k] = tmp.getPixel(xi,yi);
  108. }
  109. return 0;
  110. }