RFColor.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "vislearning/features/regionfeatures/RFColor.h"
  2. #include <iostream>
  3. using namespace OBJREC;
  4. using namespace std;
  5. using namespace NICE;
  6. RFColor::RFColor( const Config *_conf, const LocalFeature *_lf ):RegionFeatures(_conf)
  7. {
  8. lf = _lf;
  9. }
  10. void RFColor::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
  11. {
  12. fprintf (stderr, "RFColor::extract: please use ColorImage instead of GrayImage. This are Colorfeatures!!\n");
  13. exit(-1);
  14. }
  15. void RFColor::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
  16. {
  17. int rgcount = rg.size();
  18. vector<vector<int> > means;
  19. for(int i = 0; i < 3; i ++)
  20. {
  21. vector<int> m(rgcount,0);
  22. means.push_back(m);
  23. }
  24. for(int y = 0; y < cimg.height(); y++)
  25. {
  26. for(int x = 0; x < cimg.width(); x++)
  27. {
  28. int pos = mask(x,y);
  29. for(int i = 0; i < 3; i++)
  30. {
  31. means[i][(int)pos] += cimg.getPixel(x,y,i);
  32. }
  33. }
  34. }
  35. ColorImage tmp(rgcount, 1);
  36. VVector positions;
  37. for(int j = 0; j < rgcount; j++)
  38. {
  39. for(int i = 0; i < 3; i++)
  40. {
  41. tmp.setPixel(j,0,i,(int)((double)means[i][j]/(double)rg[j]->getSize()));
  42. }
  43. Vector vec(2);
  44. vec[0] = j;
  45. vec[1] = 0;
  46. positions.push_back(vec);
  47. }
  48. lf->getDescriptors(tmp, positions, feats);
  49. }
  50. RFColor::~RFColor()
  51. {
  52. }