//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; } }
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; }
//MAIN! int main(int argc, char **argv) { InitializeMagick(*argv); Image image = magickRead("test_wallpaper.jpg"); int a=0; for(a=0;a<20;a++) cout << "ahaha" << endl; ColorRGB c = image.pixelColor(0,0); cout << (double)(c.red()) << endl; cout << image.baseRows() << endl; cout << image.baseColumns() << endl; int* k = (int*) malloc(sizeof(int)*6); int i=0; for(i=0;i<6;i++) *(k+i) = i*2; getClusters(&image,k,3,1.0); image.write("test_output.png" ); return 0; }