int main( int argc, char *argv[] ) { if (argc != 3) cout << "usage:\n\tunfold INPUT_FILE OUTPUT_FILE\n"; Img input(argv[1]); Unfolder unfolder; Img *output = NULL; Img *debug = unfolder.unfold(input, output, true); // // Now rotate the image by 90 degrees. // int width = output->getWidth(); // Img* rotated = ImgOps::rotate(output, width/4, NULL); // Write output image to file. output->save(string(argv[2])); // Write debug image to file. debug->save("debug.jpg"); // Display the debug image. // ImgWindow window("Unfolder debug image"); // window.setImg(*debug); // window.refresh(); ImgWindow::waitAll(); return 0; }
bool writeImage(const std::string& path, Img& img) { if (endsWith(path, ".ptx")) { // make sure it's a power of two if (!checkPowerOfTwo(img)) return 0; // write ptx face-zero image std::string error; PtexWriter* ptx = PtexWriter::open(path.c_str(), Ptex::mt_quad, img.dt, img.nchan, img.achan, 1, error); if (!ptx) { std::cerr << error << std::endl; return 0; } ptx->setBorderModes(opt.uMode, opt.vMode); // write image top-down (flipped) int rowlen = img.w * img.nchan * Ptex::DataSize(img.dt); char* toprow = (char*) img.data + (img.h-1) * rowlen; Ptex::Res res(PtexUtils::floor_log2(img.w), PtexUtils::floor_log2(img.h)); int adjfaces[4], adjedges[4]; if (opt.uMode == Ptex::m_periodic) { adjfaces[0] = 0; adjfaces[2] = 0; adjedges[0] = 2; adjedges[2] = 0; } else { adjfaces[0] = -1; adjfaces[2] = -1; adjedges[0] = 0; adjedges[2] = 0; } if (opt.vMode == Ptex::m_periodic) { adjfaces[1] = 0; adjfaces[3] = 0; adjedges[1] = 3; adjedges[3] = 1; } else { adjfaces[1] = -1; adjfaces[3] = -1; adjedges[1] = 0; adjedges[3] = 0; } Ptex::FaceInfo finfo(res, adjfaces, adjedges); ptx->writeFace(0, finfo, toprow, -rowlen); // write meta data for (std::map<std::string,std::string>::iterator iter = opt.meta.begin(), end = opt.meta.end(); iter != end; iter++) { ptx->writeMeta(iter->first.c_str(), iter->second.c_str()); } bool ok = ptx->close(error); if (!ok) { std::cerr << error << std::endl; } ptx->release(); return ok; } else { return img.save(path); } }
float WeightedDIDCompass::computeAngle( Img *SS, Img *CV, bool useWeight ) { // Return the angle that the angle of rotation between the CV and SS by // finding the rotation of CV with the minimum difference to SS. float lowestSSD = FLT_MAX; int bestShift = 0; for ( int shift=0; shift < width; shift++ ) { ImgOps::rotate(CV, shift, &Rotated); ImgOps::sqdDiff(SS, &Rotated, &SqdDiff); if (smoothRadius > 0) ImgOps::smooth(&SqdDiff, &SqdDiffSmoothed, smoothRadius); else SqdDiffSmoothed = SqdDiff; if (useWeight) ImgOps::mult(&SqdDiffSmoothed, &FinalWeight, &SqdDiffSmoothed); float ssd = SqdDiffSmoothed.getSum(); if ( ssd < lowestSSD ) { lowestSSD = ssd; bestShift = shift; } } //if ( debug && learnIndex >= learnStart && learnIndex <= learnStop ) { if ( debug ) { Img* Temp1 = new Img(width, height); Img* Temp2 = new Img(width, height); float threshold = FinalWeight.getMax() / 4.0; Temp2 = ImgOps::threshold(&FinalWeight, threshold, Temp1); imgWindow->clear(); imgWindow->addImg("SS", *SS); imgWindow->addImg("InsWeight", InstWeight); imgWindow->addImg("FinalWeight", FinalWeight); imgWindow->addImg("Thresholded Weight", *Temp2); imgWindow->refresh(); Img* Overlay = new Img(width, height); for (int x=0; x<width; x++) { for (int y=0; y<height; y++) { if ( Temp2->get(x, y) == 1 ) Overlay->set(x, y, 1); else Overlay->set(x, y, SS->get(x,y)); } } ostringstream oss; oss << setfill('0') << setw(2); oss << learnIndex; oss << ".png"; Overlay->save("overlay" + oss.str()); FinalWeight.save("weight" + oss.str()); Temp2->save("thresholded" + oss.str()); } // A negative image rotation (rotation to the left) corresponds // to a positive angle. Hence the negative sign below. return -Angles::int2angle(bestShift, CV->getWidth()); }