void loadImages(vector<char *> filenames, int start, vector<DARY *> &images, Params *par){ // cout << filenames[start]<< endl; DARY *sim,*im; int width = par->getValue("image_width.int"); int height = par->getValue("image_height.int"); int mtop = par->getValue("header_size.int"); clock_t u = clock(); if(start==-1){ // returns two images DARY *imin = new DARY(filenames[2]); int mhight = imin->y() - par->getValue("footnote_size.int") - mtop; im = new DARY(mhight, imin->x(), UCHAR3); im->crop(imin, 0, mtop); // float scalex = width/(float)im->x(); // height = (int)(im->y()/scalex); // sim = new DARY(height,width,UCHAR3); // sim->scale(im, scalex, scalex); // delete im; images.push_back(im); imin = new DARY(filenames[4]); im = new DARY(mhight, imin->x(), UCHAR3); im->crop(imin, 0, mtop); // scalex=width/(float)im->x(); // height = (int)(im->y()/scalex); // sim=new DARY(height,width,UCHAR3); // sim->scale(im, scalex, scalex); // delete im; images.push_back(im); delete imin; } else { DARY *imin =new DARY(filenames[start]); int mhight = imin->y() - par->getValue("footnote_size.int") - mtop; //cout << mhight << endl; //int u0 = printRuntime(u, clock(), "loadImages TP0"); //cout << "x: " << imin->x() << endl; //cout << "y: " << imin->y() << endl; im = new DARY(mhight,imin->x(),UCHAR3); im->crop(imin,0,mtop); //int u1 = printRuntime(u0, clock(), "loadImages TP1"); float scalex=(float)im->x()/width; height = (int)(im->y()/scalex); sim=new DARY(height,width,UCHAR3); sim->decrease(im); //sim->writePNG("test1.png"); delete imin; //int u2 = printRuntime(u1, clock(), "loadImages TP2"); // images.push_back(sim); images.push_back(new DARY(sim)); //images[0] images.push_back(new DARY(sim)); //images[1] images.push_back(sim); // //images[2] //int u3 = printRuntime(u2, clock(), "loadImages TP3"); imin=new DARY(filenames[start+1]); //int u4a = printRuntime(u3, clock(), "loadImages TP4a"); im->crop(imin,0,mtop); //int u4b = printRuntime(u4a, clock(), "loadImages TP4b"); sim=new DARY(height,width,UCHAR3); //int u4c = printRuntime(u4b, clock(), "loadImages TP4c"); sim->decrease(im); //sim->writePNG("test2.png"); //delete imin; // commented out images.push_back(sim); //images[3] //int u4 = printRuntime(u3, clock(), "loadImages TP4"); imin=new DARY(filenames[start+2]); im->crop(imin,0,mtop); sim=new DARY(height,width,UCHAR3); sim->decrease(im); //int u5 = printRuntime(u4, clock(), "loadImages TP5"); //sim->writePNG("test3.png");getchar(); delete imin; delete im; images.push_back(sim); //images[4] // returns five images } }
void KMAcomputeShape(const boost_math::double_matrix &patch_lcpos, const boost_math::double_matrix &patch_lrpos, DARY *img, vector<float> &vec) { const int _ShapeSize = kma::shape::SrSize * kma::shape::ScSize * kma::shape::SOriSize; assert((int)vec.size() == _ShapeSize); uint patch_width = PATCH_SIZE; uint patch_height = PATCH_SIZE; assert(img->x() == patch_width && img->y() == patch_height); assert(patch_lcpos.size1() == patch_height && patch_lcpos.size2() == patch_width); assert(patch_lrpos.size1() == patch_height && patch_lrpos.size2() == patch_width); int oriSize = kma::shape::SOriSize; int rSize = kma::shape::SrSize; int cSize = kma::shape::ScSize; DARY *grad = new DARY(PATCH_SIZE,PATCH_SIZE); DARY *ori = new DARY(PATCH_SIZE,PATCH_SIZE); DARY *dx = new DARY(img->y(),img->x()); DARY *dy = new DARY(img->y(),img->x()); DARY *edge = new DARY(img->y(),img->x()); dX2(img,dx); dY2(img,dy); for(uint j=0;j<grad->y();j++){ for(uint i=0;i<grad->x();i++){ grad->fel[j][i]=sqrt(dx->fel[j][i]*dx->fel[j][i]+dy->fel[j][i]*dy->fel[j][i]); ori->fel[j][i]=atan2(dy->fel[j][i],dx->fel[j][i]); } } /* initialize edge image */ memset(edge->fel[0], 0, edge->x()*edge->y()*sizeof(float)); cannyEdges(dx, dy, grad, edge, 5, 15); delete dx; delete dy; delete grad; /* begin of KeyLogPolSample(vec, edge, ori, angle, SOriSize, SrSize, ScSize); */ int iradius = (int)floor(PATCH_SIZE/2); for (int i = -iradius; i <= iradius; i++) for (int j = -iradius; j <= iradius; j++) { // lcpos=(M_PI+atan2(rpos,cpos))*cspacing; // lrpos=log(1+sqrt((float)i*i+j*j)/iradius)*rSize; double lcpos = patch_lcpos(iradius + j, iradius + i); double lrpos = patch_lrpos(iradius + j, iradius + i); double rx = lrpos;// + (rSize - 1) / 2.0; double cx = lcpos;// + (cSize - 1) / 2.0; if (rx > -1.0 && rx < (float) rSize && cx > -1.0 && cx < (float) cSize) { //cout << "in" << cpos << " " << rpos << endl; KMAAddLogPolSample(vec, edge, ori, 0.0, iradius + i, iradius + j, lrpos, lcpos, /* not used ? */ lrpos, lcpos, /* rx, cx */ oriSize, rSize, cSize); } } /* end of KeyLogPolSample */ delete edge; delete ori; KMANormalizeVect(vec); int intval, changed = FALSE; //for (int i = 0; i < kma::shape::ShapeSize; i++) for (int i = 0; i < _ShapeSize; i++) if (vec[i] > kma::shape::MaxIndexVal) { vec[i] = kma::shape::MaxIndexVal; changed = TRUE; } if (changed) { KMANormalizeVect(vec); } /* Convert float vector to integer. Assume largest value in normalized vector is likely to be less than 0.5. */ //for (int i = 0; i < kma::shape::ShapeSize; i++) { for (int i = 0; i < _ShapeSize; i++) { intval = (int) (512.0 * vec[i]); vec[i] = (255 < intval) ? 255 : intval; } }