int main(int argc, char *argv[]){ LARGE_INTEGER frequency; LARGE_INTEGER t1, t2; double elapsedTime; int ret = 0; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&t1); if(argc != 2){ printhelp(); return EXIT_FAILURE; } startLogger("log.txt"); readSettingsFromConfigFile(argv[1]); setUpSpectrum(); logIt(DEBUG, "pathToSlice=%s", cfg.pathToSlice); logIt(DEBUG, "pathToOutputReconstruction=%s", cfg.pathToOutputReconstruction); setUpAttenuation(); logIt(INFO, "Everything set up successfully. Starting simulation..."); ret = simulation(cfg.pathToSlice, cfg.pathToOutputSinogram); reconstruction(cfg.pathToOutputSinogram, cfg.pathToOutputReconstruction); QueryPerformanceCounter(&t2); elapsedTime = (double)(t2.QuadPart - t1.QuadPart) / frequency.QuadPart; logIt(INFO, "Total computation time: %f seconds.", elapsedTime); logIt(INFO, "Reconstructed image saved as %s. Exiting...", cfg.pathToOutputReconstruction); logIt(DEBUG, "main(int argc, char *argv[]) finished."); stopLogger(); return ret; }
void main_constz() { string gen_name, det_name, root_name; string gen_prefix = "events_z"; string det_prefix = "measures_z"; string root_prefix = "reconstruction_z"; string str_buff; string str_dat = ".dat"; string str_root = ".root"; stringstream ss; double z_val; for (int i = 0; i <= 30; i++) { z_val = double(i); cout << "Starting analysis with z = " << z_val << "..." << endl; ss << z_val; ss >> str_buff; gen_name = gen_prefix + str_buff; det_name = det_prefix + str_buff; root_name = root_prefix + str_buff; ss.clear(); cout << '\t' << "Generation..." << '\n' << endl; generation(gen_name.c_str(), "CONST Z"); cout << '\t' << "Detector response..." << '\n' << endl; detector(gen_name.c_str(), det_name.c_str()); cout << '\t' << "Reconstruction..." << '\n' << endl; reconstruction(gen_name.c_str(), det_name.c_str(), root_name.c_str()); cout << '\n' << "-------------------------" << '\n' << endl; } }
int main(int argc, char* argv[]) { std::ifstream in((argc>1)?argv[1]:"data/half.xyz"); std::istream_iterator<Point_3> begin(in); std::istream_iterator<Point_3> end; Perimeter perimeter(0.5); Triangulation_3 dt(begin, end); Reconstruction reconstruction(dt, perimeter); reconstruction.run(); std::cout << reconstruction.number_of_outliers() << " outliers:\n" << std::endl; BOOST_FOREACH(const Point_3& p, reconstruction.outliers()){ std::cout << p << std::endl; } std::cout << "Boundaries:" << std::endl ; BOOST_FOREACH(const Vertex_on_boundary_range & vobr, reconstruction.boundaries()){ std::cout << "boundary\n"; // As we use BOOST_FOREACH we do not use the type Boundary_range BOOST_FOREACH(Vertex_handle v, vobr){ std::cout << v->point() << std::endl; } }
int main(int argc, char* argv[]) { std::ifstream in((argc>1)?argv[1]:"data/half.xyz"); std::istream_iterator<Point_3> begin(in); std::istream_iterator<Point_3> end; Triangulation_3 dt(begin,end); Reconstruction reconstruction(dt); reconstruction.run(); const TDS_2& tds = reconstruction.triangulation_data_structure_2(); std::cout << "solid produced with CGAL::Advancing_front_surface_reconstruction\n"; for(TDS_2::Face_iterator fit = tds.faces_begin(); fit != tds.faces_end(); ++fit){ if(reconstruction.has_on_surface(fit)){ Triangulation_3::Facet f = fit->facet(); Triangulation_3::Cell_handle ch = f.first; int ci = f.second; Point_3 points[3]; for(int i = 0, j = 0; i < 4; i++){ if(ci != i){ points[j] = ch->vertex(i)->point(); j++; } } std::cout << " facet normal " << CGAL::unit_normal(points[0],points[1], points[2]) << "\n" << " outer loop\n" << " vertex " << points[0] << "\n" << " vertex " << points[1] << "\n" << " vertex " << points[2] << "\n" << " endloop\n" << " endfacet\n"; } } std::cout << "endsolid" << std::endl; return 0; }
int draw_reconstruction_bitmap(PSIRT *psirt) { int i=0,j=0; double* pixel_intensity = reconstruction(psirt); // DESENHAR bmpfile_t *bmp = bmp_create(RES_X, RES_Y, 24); for (i = 0; i < RES_X; i++) { for (j = 0; j < RES_Y; j++) { double pixel = pixel_intensity[i + (j * RES_X)]; // Alternativa 1: função linear simples int paint_of_choice = (pixel * 255); // Alternativa 2: função polinomial #ifdef REC_PAINT_POLY paint_of_choice = pow(pixel, 2) * 255; #endif // Alternativa 3: função exponencial #ifdef REC_PAINT_EXP paint_of_choice = pow(pixel, pixel) * 255; #endif // Alternativa 3: função customizada #ifdef REC_PAINT_CUSTOM paint_of_choice = 255; if (pixel < .2) paint_of_choice = 0; else if (pixel < .4) paint_of_choice = 255 / 4; #endif rgb_pixel_t pix = { paint_of_choice, paint_of_choice, paint_of_choice, 0 }; bmp_set_pixel(bmp, i, j, pix); } } bmp_save(bmp, "psirt_output.bmp"); bmp_destroy(bmp); free(pixel_intensity); return i; }
/** perform reconstruction */ int rec(void) { std::string file_name = po.get("source"); std::cout << "loading source..." <<std::endl; std::auto_ptr<ImageModel> handle(new ImageModel); if (!handle->load_from_file(file_name.c_str())) { std::cout << "Load src file failed:" << handle->error_msg << std::endl; return 1; } std::cout << "src loaded" <<std::endl; if (po.has("flip")) { std::string flip_seq = po.get("flip"); for(unsigned int index = 0;index < flip_seq.length();++index) if(flip_seq[index] >= '0' && flip_seq[index] <= '5') { handle->flip(flip_seq[index]-'0'); std::cout << "Flip image volume:" << (int)flip_seq[index]-'0' << std::endl; } } // apply affine transformation if (po.has("affine")) { std::cout << "reading transformation matrix" <<std::endl; std::ifstream in(po.get("affine").c_str()); std::vector<double> T((std::istream_iterator<float>(in)), (std::istream_iterator<float>())); if(T.size() != 12) { std::cout << "Invalid transfformation matrix." <<std::endl; return 1; } image::transformation_matrix<double> affine; affine.load_from_transform(T.begin()); std::cout << "rotating images" << std::endl; handle->rotate(handle->voxel.dim,affine); } float param[4] = {0,0,0,0}; int method_index = 0; method_index = po.get("method",int(0)); std::cout << "method=" << method_index << std::endl; if(method_index == 0) // DSI param[0] = 17.0; if(method_index == 2) { param[0] = 5; param[1] = 15; } if(method_index == 3) // QBI-SH { param[0] = 0.006; param[1] = 8; } if(method_index == 4) param[0] = 1.2; if(method_index == 6) // Convert to HARDI { param[0] = 1.25; param[1] = 3000; param[2] = 0.05; } if(method_index == 7) { if (po.has("template")) { std::cout << "loading external template:" << po.get("template") << std::endl; fa_template_imp.template_file_name = po.get("template"); } if(!fa_template_imp.load_from_file()) { std::cout << "failed to locate template for QSDR reconstruction" << std::endl; return -1; } param[0] = 1.2; param[1] = 2.0; std::fill(handle->mask.begin(),handle->mask.end(),1.0); } param[3] = 0.0002; if(po.get("deconvolution",int(0))) { param[2] = 7; } if(po.get("decomposition",int(0))) { param[3] = 0.05; param[4] = 10; } if (po.has("param0")) { param[0] = po.get("param0",float(0)); std::cout << "param0=" << param[0] << std::endl; } if (po.has("param1")) { param[1] = po.get("param1",float(0)); std::cout << "param1=" << param[1] << std::endl; } if (po.has("param2")) { param[2] = po.get("param2",float(0)); std::cout << "param2=" << param[2] << std::endl; } if (po.has("param3")) { param[3] = po.get("param3",float(0)); std::cout << "param3=" << param[3] << std::endl; } if (po.has("param4")) { param[4] = po.get("param4",float(0)); std::cout << "param4=" << param[4] << std::endl; } handle->voxel.ti.init(po.get("odf_order",int(8))); handle->voxel.need_odf = po.get("record_odf",int(0)); handle->voxel.output_jacobian = po.get("output_jac",int(0)); handle->voxel.output_mapping = po.get("output_map",int(0)); handle->voxel.output_diffusivity = po.get("output_dif",int(1)); handle->voxel.output_tensor = po.get("output_tensor",int(0)); handle->voxel.output_rdi = po.get("output_rdi",int(1)); handle->voxel.odf_deconvolusion = po.get("deconvolution",int(0)); handle->voxel.odf_decomposition = po.get("decomposition",int(0)); handle->voxel.max_fiber_number = po.get("num_fiber",int(5)); handle->voxel.r2_weighted = po.get("r2_weighted",int(0)); handle->voxel.reg_method = po.get("reg_method",int(0)); handle->voxel.interpo_method = po.get("interpo_method",int(2)); handle->voxel.csf_calibration = po.get("csf_calibration",int(0)) && method_index == 4; std::vector<unsigned int> shell; calculate_shell(handle->voxel.bvalues,shell); handle->voxel.half_sphere = po.get("half_sphere", int(((shell.size() > 5) && (shell[1] - shell[0] <= 3)) ? 1:0)); handle->voxel.scheme_balance = po.get("scheme_balance", int((shell.size() <= 5) && !shell.empty() && handle->voxel.bvalues.size()-shell.back() < 100 ? 1:0)); { if(handle->voxel.need_odf) std::cout << "record ODF in the fib file" << std::endl; if(handle->voxel.odf_deconvolusion) std::cout << "apply deconvolution" << std::endl; if(handle->voxel.odf_decomposition) std::cout << "apply decomposition" << std::endl; if(handle->voxel.r2_weighted && method_index == 4) std::cout << "r2 weighted is used for GQI" << std::endl; } if(po.has("other_image")) { QStringList file_list = QString(po.get("other_image").c_str()).split(";"); for(unsigned int i = 0;i < file_list.size();++i) { QStringList name_value = file_list[i].split(","); if(name_value.size() != 2) { std::cout << "Invalid command: " << file_list[i].toStdString() << std::endl; return 0; } if(!add_other_image(handle.get(),name_value[0],name_value[1],true)) return 0; } } if(po.has("mask")) { std::string mask_file = po.get("mask"); std::cout << "reading mask..." << mask_file << std::endl; gz_nifti header; if(header.load_from_file(mask_file.c_str())) { image::basic_image<unsigned char,3> external_mask; header.toLPS(external_mask); if(external_mask.geometry() != handle->voxel.dim) std::cout << "In consistent the mask dimension...using default mask" << std::endl; else handle->mask = external_mask; } else std::cout << "fail reading the mask...using default mask" << std::endl; } if(po.get("motion_correction",int(0))) { std::vector<image::affine_transform<double> > arg; unsigned int progress = 0; bool terminated = false; std::cout << "correct for motion and eddy current..." << std::endl; rec_motion_correction(handle.get(),po.get("thread_count",int(std::thread::hardware_concurrency())), arg,progress,terminated); std::cout << "Done." <<std::endl; } std::cout << "start reconstruction..." <<std::endl; const char* msg = reconstruction(handle.get(),method_index, param,po.get("check_btable",int(1)), po.get("thread_count",int(std::thread::hardware_concurrency()))); if (!msg) std::cout << "Reconstruction finished:" << msg << std::endl; return 0; }
int main(int, char**) { cv::VideoCapture cap(1); // open the default camera if(!cap.isOpened()){ // check if we succeeded std::cout << "Cannot open the camera ! " << std::endl; return -1; } cv::Mat frame; // Matrice dans laquelle on va récupérer l'image while(true) { cap >> frame; segmentation(frame); cv::namedWindow("images",CV_WINDOW_AUTOSIZE); cv::imshow("images", frame); //cv::imwrite("/usr/users/promo2016/pierrard_reg/TL/test.png", frame); std::vector<std::vector<cv::Point>> contours; // variable dans laquelle on récupèrera la liste des contours cv::Mat frame_conv; // variable qui va contenir l'image en nuances de gris cv::cvtColor(frame, frame_conv, CV_RGB2GRAY); // conversion de l'image courante en couleur en niveaux de gris cv::findContours(frame_conv, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); cv::Scalar color( rand()&255, rand()&255, rand()&255 ); // définition d'une couleur tirée aléatoirement cv::Mat dst = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC3); // Matrice qui va afficher le contour le plus long if (contours.size() != 0) { contours = find_longest_contour(contours); cv::drawContours(dst, contours, -1, color); std::vector<std::complex<double>> coeff = descripteur_fourier_normal(contours, 10); double scale = 0.25 * std::min(frame.cols, frame.rows); // coefficient multiplicateur permettant d'obtenir des valeurs plus espacées des coordonnées des points std::vector<std::vector<cv::Point>> contfil = reconstruction(coeff, 200, 10, z_moyen(contours), scale); // on récupère les points du contour reconstruit cv::Mat dst2 = cv::Mat::zeros(frame.rows, frame.cols, CV_8UC3); // Matrice dans laquelle on affichera le contour reconstruit cv::drawContours(dst2, contfil, -1, color); cv::namedWindow("contours",CV_WINDOW_AUTOSIZE); cv::imshow("contours", dst); cv::namedWindow("reconstruction",CV_WINDOW_AUTOSIZE); cv::imshow("reconstruction", dst2); } if(cv::waitKey(30) >= 0) break; } /* int c_max = 10; std::map< std::string, std::vector< std::vector< std::complex<double> > > > database = fourier_descriptor_extraction(c_max); for (auto& it : database) { std::cout << it.first << " : " << std::endl;; for (auto& it2 : it.second[0]) { std::cout << it2 << ", "; } std::cout << std::endl; }*/ return 0; }
bool CalculationThread::singleStep(int x, int y) { if(!seedmap) init(); Patch* block = 0; if(x==-1) block = seedmap->matchNext(); else { int xlocal = ((float)x/400.0) * (seedmap->sourceImage_.size().width / blockSize_); int ylocal = ((float)y/400.0) * (seedmap->sourceImage_.size().height / blockSize_); block = seedmap->getPatch(xlocal,ylocal); seedmap->match(block); } if (!block) return false; if (!block->matches_) return true; cv::Mat tmpImage = base_.clone(); float colorScale = 255.0 / seedmap->crit_.maxError_; if(!block->finalMatch_) { for(uint i=0; i<block->matches_->size(); i++) { Match* match = block->matches_->at(i); Polygon hull = match->hull_; // highlight match for(int j=0; j<4; j++) cv::line(tmpImage, hull.verts[j], hull.verts[(j+1) % 4], cv::Scalar(0,255-match->error_*colorScale,match->error_*colorScale,100)); foreach(cv::Point2f p, block->pointsSrc_) cv::line(tmpImage, p+cv::Point2f(block->x_,block->y_), p+cv::Point2f(block->x_,block->y_), cv::Scalar(0,155,00,100)); } } if(block->finalMatch_) { // highlight match cv::Mat selection(block->finalMatch_->t_.transformMat_, cv::Rect(0,0,3,2)); cv::Mat inverted; invertAffineTransform(selection, inverted); for (int i=0; i<2; i++) for(int j=0; j<3; j++) std::cout << inverted.at<float>(i,j) << " "; for(int j=0; j<4; j++) std::cout << block->finalMatch_->hull_.verts[j].m_v[0] << " " << block->finalMatch_->hull_.verts[j].m_v[1] << std::endl; for(int j=0; j<4; j++) cv::line(tmpImage, block->finalMatch_->hull_.verts[j], block->finalMatch_->hull_.verts[(j+1) % 4], cv::Scalar(100,255,0,100)); } debugWidgetR->fromIpl( tmpImage, "preview" ); debugWidgetR->updateGL(); cv::Mat reconstruction(seedmap->debugReconstruction()); debugWidgetL->fromIpl( reconstruction, "reconstruction" ); debugWidgetL->updateGL(); return true; }