Beispiel #1
0
//inherited from BaseFeature
void ImageFeature::load(const ::std::string& filename, bool forceGray){
  //temporary pixel data
  ColorGray grayPixel;
  ColorRGB rgbPixel;
  
  if(filename.find("gray") < filename.size()) {
    forceGray=true;
  }
  
  //temporary image data
  Image loaded;
  // try {
    loaded.read(filename);
    //  } catch( Exception &error_ ) {
    // ERR << "Exception loading image: " << error_.what() << endl;
    // return;
    // }
  
  xsize_=loaded.columns();
  ysize_=loaded.rows();
  if(loaded.colorSpace()==RGBColorspace && !forceGray) {
    zsize_=3;
    DBG(30) << "found image in RGB" << endl;
  } else if ( loaded.colorSpace()==GRAYColorspace || forceGray) {
    DBG(30) << "found image in gray" << endl;
    zsize_=1;
  } else {
    ERR << "Unknown color space" << loaded.colorSpace() << endl;
  }
  
  data_.resize(zsize_);
  for(uint c=0;c<zsize_;++c) data_[c].resize(xsize_*ysize_);
  
  switch(zsize_) {
  case 1: //gray image
    DBG(30) << "Loading gray image" << endl;
    for(uint y=0;y<ysize_;++y) {
      for(uint x=0;x<xsize_;++x) {
        rgbPixel=loaded.pixelColor(x,y);
        data_[0][y*xsize_+x]=(rgbPixel.red()+rgbPixel.green()+rgbPixel.blue())/3;
      }
    }
    break;
  case 3: //rgb image
    DBG(30) << "Loading rgb image" << endl;
    for(uint y=0;y<ysize_;++y) {
      for(uint x=0;x<xsize_;++x) {
        rgbPixel=loaded.pixelColor(x,y);
        data_[0][y*xsize_+x]=rgbPixel.red();
        data_[1][y*xsize_+x]=rgbPixel.green();
        data_[2][y*xsize_+x]=rgbPixel.blue();
      }
    }
    break;
  default:
    ERR << "Unknown image format, depth=" << zsize_ << endl;
    break;
  }
}
Beispiel #2
0
double getColorDistance(ColorRGB color1, ColorRGB color2) {
  cout << "getting color distance" << endl;
  double distance = pow(color1.red()-color2.red(),2);
  distance += pow(color1.blue()-color2.blue(),2);
  distance += pow(color1.green()-color2.green(),2);
  cout << "distance is " << distance << endl;
  return distance;
}