GPX_model::retCode_e ACTFile::load(ifstream* fp, GPX_model* gpxm) { GPX_trkType trk(gpxm->trk.size()); T_uXml uXML; UXML_init(&uXML); uXML.fp = fp; uXML.getChar = getChar; uXML.pContent = gBuffer; uXML.maxContent = BUFFER_SIZE; uXML.openTag = openTag; uXML.closeTag = closeTag; uXML.setContent = tagContent; uXML.state = PARSING_NONE; uXML.pObject = gpxm; gTime = getStartDateTime(0, NULL); gTrkseg = NULL; gPointIndex = 0; memset(gSegementEndIndexes, 0, sizeof(unsigned int) * MAX_SEGMENTS); // add track gpxm->trk.push_back(trk); // parse file if (UXML_parseFile(&uXML) != 0) return GPX_model::GPXM_ERR_FAILED; // update track gpxm->updateTrack(gpxm->trk.back()); return GPX_model::GPXM_OK; }
void CorrectedRadialProfileTest() { // read image const char* imgname = "SingleBead.jpg"; ImageData img = ReadJPEGFile(imgname); // localize CPUTracker trk(img.w,img.h); trk.SetImageFloat(img.data); vector2f com = trk.ComputeMeanAndCOM(); bool boundaryHit; vector2f qi = trk.ComputeQI(com, 4, 64, 64,ANGSTEPF, 1, 30, boundaryHit); dbgprintf("%s: COM: %f, %f. QI: %f, %f\n", imgname, com.x, com.y, qi.x, qi.y); std::vector<float> angularProfile(128); float asym = trk.ComputeAsymmetry(qi, 64, angularProfile.size(), 1, 30, &angularProfile[0]); // ComputeAngularProfile(&angularProfile[0], 64, angularProfile.size(), 1, 30, qi, &img, trk.mean); WriteImageAsCSV("angprof.csv", &angularProfile[0], angularProfile.size(), 1); dbgprintf("Asymmetry value: %f\n", asym); std::vector<float> crp(128); float* crpmap = new float[angularProfile.size()*crp.size()]; ComputeCRP(&crp[0], crp.size(), angularProfile.size(), 1, 30, qi, &img, 0.0f); WriteImageAsCSV("crpmap.csv", crpmap, crp.size(), angularProfile.size()); delete[] crpmap; delete[] img.data; //CRP_TestGeneratedData(); // GenerateImageFromLUT(ImageData(img,w,h), ImageData }
void ScatterBiasArea(int roi, float scan_width, int steps, int samples, int qi_it, float angstep) { std::vector<float> u=linspace(roi/2-scan_width/2,roi/2+scan_width/2, steps); QTrkComputedConfig cfg; cfg.width=cfg.height=roi; cfg.qi_angstep_factor = angstep; cfg.qi_iterations = qi_it; cfg.qi_angular_coverage = 0.7f; cfg.qi_roi_coverage = 1; cfg.qi_radial_coverage = 1.5f; cfg.qi_minradius=0; cfg.zlut_minradius=0; cfg.zlut_angular_coverage = 0.7f; cfg.zlut_roi_coverage = 1; cfg.zlut_radial_coverage = 1.5f; cfg.zlut_minradius = 0; cfg.qi_minradius = 0; cfg.com_bgcorrection = 0; cfg.xc1_profileLength = roi*0.8f; cfg.xc1_profileWidth = roi*0.2f; cfg.xc1_iterations = 1; cfg.Update(); ImageData lut,orglut = ReadLUTFile("10x.radialzlut#4"); vector3f ct(roi/2,roi/2,lut.h/2 + 0.123f); float dx = scan_width/steps; QueuedCPUTracker trk(cfg); ResampleLUT(&trk, &orglut, orglut.h, &lut); int maxval = 10000; ImageData tmp=ImageData::alloc(roi,roi); GenerateImageFromLUT(&tmp, &lut, 0, cfg.zlut_maxradius, vector3f(roi/2,roi/2,lut.h/2)); ApplyPoissonNoise(tmp, maxval); std::string fn = SPrintf( "sb_area_roi%d_scan%d_steps%d_qit%d_N%d", roi, (int)scan_width, steps, qi_it, samples); WriteJPEGFile( (fn + ".jpg").c_str(), tmp); tmp.free(); fn += ".txt"; for (int y=0;y<steps;y++) { for (int x=0;x<steps;x++) { vector3f cpos( (x+0.5f-steps/2) * dx, (y+0.5f-steps/2) * dx, 0 ); cfg.qi_iterations = qi_it; auto r= AccBiasTest(orglut, &trk, samples, cpos+ct, vector3f(), 0, maxval, qi_it < 0 ? LT_XCor1D : 0); float row[] = { r.acc.x, r.acc.y, r.acc.z, r.bias.x, r.bias.y, r.bias.z, r.crlb.x, r.crlb.z, samples }; WriteArrayAsCSVRow(fn.c_str(), row, 9, x+y>0); dbgprintf("X=%d,Y=%d\n", x,y); } } orglut.free(); lut.free(); }
void WriteRadialProf(const char *file, ImageData& d) { CPUTracker trk(d.w,d.h); trk.SetImageFloat(d.data); vector2f com = trk.ComputeMeanAndCOM(); bool bhit; vector2f qipos = trk.ComputeQI(com, 4, 64, 64,ANGSTEPF, 5, 50, bhit); const int radialsteps=64; float radprof[radialsteps]; trk.ComputeRadialProfile(radprof, radialsteps, 128, 5, 40, qipos, false); WriteImageAsCSV(file, radprof, radialsteps, 1); }
void BuildConvergenceMap(int iterations) { int W=80, H=80; char* data=new char[W*H]; FILE* f=fopen("singlebead.bin", "rb"); fread(data,1,80*80,f); fclose(f); float testrange=20; int steps=100; float step=testrange/steps; vector2f errXCor, errQI; CPUTracker trk(W,H,40); // Get a good starting estimate trk.SetImage8Bit((uchar*)data,W); vector2f com = trk.ComputeMeanAndCOM(); bool boundaryHit; vector2f cmp = trk.ComputeQI(com,8,80,64,ANGSTEPF,2,25,boundaryHit); float *xcorErrMap = new float[steps*steps]; float *qiErrMap = new float[steps*steps]; for (int y=0;y<steps;y++){ for (int x=0;x<steps;x++) { vector2f initial (cmp.x+step*(x-steps/2), cmp.y+step*(y-steps/2) ); vector2f xcor = trk.ComputeXCorInterpolated(initial, iterations, 64, boundaryHit); vector2f qi = trk.ComputeQI(initial, iterations, 80, 64,ANGSTEPF,2,30,boundaryHit); errXCor.x += fabs(xcor.x-cmp.x); errXCor.y += fabs(xcor.y-cmp.y); xcorErrMap[y*steps+x] = distance(xcor,cmp); errQI.x += fabs(qi.x-cmp.x); errQI.y += fabs(qi.y-cmp.y); qiErrMap[y*steps+x] = distance(qi,cmp); } dbgprintf("y=%d\n", y); } WriteImageAsCSV(SPrintf("xcor-err-i%d.csv", iterations).c_str(), xcorErrMap, steps,steps); WriteImageAsCSV(SPrintf("qi-err-i%d.csv", iterations).c_str(), qiErrMap, steps,steps); delete[] qiErrMap; delete[] xcorErrMap; delete[] data; }
void GetPositionAtTOF(AliESDtrack *t,Float_t mag,Double_t pos[3]){ const AliExternalTrackParam* trkExt = t->GetOuterParam(); Float_t rTOFused=370; AliExternalTrackParam trk(*trkExt); Int_t value = trk.PropagateTo(370,mag); // printf("propto = %i\n",value); while(!value && rTOFused > 0){ rTOFused-=1; value = trk.PropagateTo(rTOFused,mag); // printf("re-propto = %i (%f)\n",value,rTOF); } trk.GetXYZ(pos); }
void TestBias() { ImageData lut = ReadLUTFile("lut000.jpg"); ImageData img = ImageData::alloc(80,80); CPUTracker trk(img.w,img.h); float o = 2.03f; vector3f pos (img.w/2+o, img.h/2+o, lut.h/2); NormalizeZLUT(lut.data, 1, lut.h, lut.w); lut.normalize(); srand(time(0)); for (int i=0;i<10;i++) { GenerateImageFromLUT(&img, &lut, 0, img.w/2, pos, true); ApplyPoissonNoise(img, 11050); float stdev = StdDeviation(img.data, img.data + img.w); dbgprintf("Noise level std: %f\n",stdev); } WriteJPEGFile("TestBias-smp.jpg", img); trk.SetImageFloat(img.data); vector2f com = trk.ComputeMeanAndCOM(); dbgprintf("COM: x:%f, y:%f\n", com.x,com.y); bool bhit; auto rw = ComputeRadialBinWindow(img.w); vector2f qi = trk.ComputeQI(com, 3, img.w, 3*img.w/4, 1, 0, img.w/2, bhit, &rw[0]); dbgprintf("QI: x: %f, y:%f\n", qi.x,qi.y); trk.SetRadialZLUT(lut.data, lut.h, lut.w, 1, 0, img.w/2, true, false); float z = trk.ComputeZ(qi,3*img.w, 0, 0, 0, 0, false); float znorm = trk.ComputeZ(qi,3*img.w, 0, 0, 0, 0, true); dbgprintf("Z: %f, ZNorm: %f, true:%f\n", z, znorm, pos.z); img.free(); lut.free(); }
void GenerateZLUTFittingCurve(const char *lutfile) { QTrkSettings settings; settings.width = settings.height = 80; QueuedCPUTracker qt(settings); ImageData lut = ReadJPEGFile(lutfile); ImageData nlut; ResampleLUT(&qt, &lut, lut.h, &nlut); CPUTracker trk(settings.width,settings.height); ImageData smp = ImageData::alloc(settings.width,settings.height); trk.SetRadialZLUT(nlut.data, nlut.h, nlut.w, 1, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, false, false); int N=8; for (int z=0;z<6;z++) { vector3f pos(settings.width/2,settings.height/2, nlut.h * (1+z) / (float)N + 0.123f); GenerateImageFromLUT(&smp, &nlut, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, pos); ApplyPoissonNoise(smp, 10000); WriteJPEGFile( SPrintf("zlutfitcurve-smpimg-z%d.jpg", z).c_str(), smp); trk.SetImageFloat(smp.data); std::vector<float> profile(qt.cfg.zlut_radialsteps), cmpProf(nlut.h), fitted(nlut.h); trk.ComputeRadialProfile(&profile[0], qt.cfg.zlut_radialsteps, qt.cfg.zlut_angularsteps, qt.cfg.zlut_minradius, qt.cfg.zlut_maxradius, pos.xy(), false); trk.LUTProfileCompare(&profile[0], 0, &cmpProf[0], CPUTracker::LUTProfMaxQuadraticFit, &fitted[0]); WriteArrayAsCSVRow("zlutfitcurve-profile.txt", &profile[0], profile.size(), z>0); WriteArrayAsCSVRow("zlutfitcurve-cmpprof.txt", &cmpProf[0], cmpProf.size(), z>0); WriteArrayAsCSVRow("zlutfitcurve-fitted.txt", &fitted[0], fitted.size(), z>0); } smp.free(); nlut.free(); lut.free(); }
void TestZRangeBias(const char *name, const char *lutfile, bool normProf) { ImageData lut = ReadLUTFile(lutfile); QTrkComputedConfig settings; settings.width=settings.height=100; settings.Update(); ImageData img=ImageData::alloc(settings.width,settings.height); CPUTracker trk(settings.width,settings.height); NormalizeZLUT(lut.data, 1, lut.h, lut.w); trk.SetRadialZLUT(lut.data, lut.h, lut.w, 1, 1, settings.qi_maxradius, true, false); float* prof= ALLOCA_ARRAY(float,lut.w); int N=1000; std::vector< vector2f> results (N); for (int i=0;i<N;i++) { vector3f pos (settings.width/2, settings.height/2, i/(float)N*lut.h); GenerateImageFromLUT(&img, &lut, 1, settings.qi_maxradius, pos); if(InDebugMode&&i==0){ WriteJPEGFile(SPrintf("%s-smp.jpg",name).c_str(),img); } trk.SetImageFloat(img.data); //trk.ComputeRadialProfile(prof,lut.w,settings.zlut_angularsteps, settings.zlut_minradius, settings.zlut_maxradius, pos.xy(), false); //float z=trk.LUTProfileCompare(prof, 0, 0, normProf ? CPUTracker::LUTProfMaxSplineFit : CPUTracker::LUTProfMaxQuadraticFit); result: splines no go! float z = trk.ComputeZ(pos.xy(), settings.zlut_angularsteps, 0, 0, 0, 0,true); results[i].x = pos.z; results[i].y = z-pos.z; } WriteImageAsCSV(SPrintf("%s-results.txt", name).c_str(),(float*) &results[0], 2, N); lut.free(); img.free(); }
int main(int ac, char *av[]) { { int pos = 0; for(int index = 0;av[0][index];++index) if(av[0][index] == '\\' || av[0][index] == '/') pos = index; program_base = std::string(&(av[0][0]),&(av[0][0])+pos+1); } if(ac > 2) { { std::cout << "DSI Studio " << __DATE__ << ", Fang-Cheng Yeh" << std::endl; // options for general options po::options_description desc("reconstruction options"); desc.add_options() ("help", "help message") ("action", po::value<std::string>(), "rec:diffusion reconstruction trk:fiber tracking") ("source", po::value<std::string>(), "assign the .src or .fib file name") ; po::variables_map vm; po::store(po::command_line_parser(ac, av).options(desc).allow_unregistered().run(),vm); if (vm.count("help")) { std::cout << "example: perform reconstruction" << std::endl; std::cout << " --action=rec --source=test.src.gz --method=4 " << std::endl; std::cout << "options:" << std::endl; rec(0,0); std::cout << "example: perform fiber tracking" << std::endl; std::cout << " --action=trk --source=test.src.gz.fib.gz --method=0 --fiber_count=5000" << std::endl; std::cout << "options:" << std::endl; trk(0,0); return 1; } if (!vm.count("action") || !vm.count("source")) { std::cout << "invalid command, use --help for more detail" << std::endl; return 1; } if(vm["action"].as<std::string>() == std::string("rec")) return rec(ac,av); if(vm["action"].as<std::string>() == std::string("trk")) return trk(ac,av); if(vm["action"].as<std::string>() == std::string("src")) return src(ac,av); if(vm["action"].as<std::string>() == std::string("ana")) return ana(ac,av); } return 1; } QApplication::setStyle(new QCleanlooksStyle); QApplication a(ac,av); a.setOrganizationName("LabSolver"); a.setApplicationName("DSI Studio"); QFont font; font.setFamily(QString::fromUtf8("Arial")); a.setFont(font); if(!load_fa_template()) return -1; MainWindow w; w.setFont(font); w.showMaximized(); w.setWindowTitle(QString("DSI Studio ") + __DATE__ + " build"); return a.exec(); }
void GetResolutionAtTOF(AliESDtrack *t,Float_t mag,Int_t tofc,Float_t res[3]){ Int_t detId[5]; AliTOFGeometry::GetVolumeIndices(tofc,detId); Float_t xTOFch[3]; xTOFch[0] = AliTOFGeometry::GetX(detId); xTOFch[1] = AliTOFGeometry::GetY(detId); xTOFch[2] = AliTOFGeometry::GetZ(detId); Float_t rTOF = TMath::Sqrt(xTOFch[0]*xTOFch[0] + xTOFch[1]*xTOFch[1]); rTOFused = rTOF; secAngle = (Int_t (TMath::ATan2(xTOFch[1],xTOFch[0])/TMath::Pi()*9)+ 0.5) * TMath::Pi() / 9; Float_t thetaAngle = AliTOFGeometry::GetAngles(detId[1]/*iplate*/, detId[2]/*istrip*/)/180*TMath::Pi(); Float_t versX[3] = {TMath::Sin(secAngle),-TMath::Cos(secAngle),0}; Float_t versY[3] = {TMath::Cos(thetaAngle)*TMath::Cos(secAngle),TMath::Cos(thetaAngle)*TMath::Sin(secAngle),-TMath::Sin(thetaAngle)}; Float_t versZ[3] = {TMath::Sin(thetaAngle)*TMath::Cos(secAngle),TMath::Sin(thetaAngle)*TMath::Sin(secAngle),TMath::Cos(thetaAngle)}; Double_t cv[21]; const AliExternalTrackParam* trkExt = t->GetOuterParam(); AliExternalTrackParam trk(*trkExt); Int_t value = trk.PropagateTo(rTOF,mag); // printf("propto = %i\n",value); while(!value && rTOFused > 0){ rTOFused-=1; value = trk.PropagateTo(rTOFused,mag); // printf("re-propto = %i (%f)\n",value,rTOF); } trk.GetCovarianceXYZPxPyPz(cv); Double_t pos[3]; trk.GetXYZ(pos); Float_t pos2[] = {pos[0],pos[1],pos[2]}; // printf("residuals recomputed at %f: %f %f (%f %f)\n",sqrt(pos[0]*pos[0]+pos[1]*pos[1]),AliTOFGeometry::GetPadDx(pos2),AliTOFGeometry::GetPadDz(pos2),t->GetTOFsignalDx(),t->GetTOFsignalDz()); for(Int_t i=0;i<5;i++) cval[i] = cv[i]; Float_t mat[3][3]; mat[0][0] = cv[0]; mat[0][1] = cv[1]; mat[0][2] = cv[3]; mat[1][0] = cv[1]; mat[1][1] = cv[2]; mat[1][2] = cv[4]; mat[2][0] = cv[3]; mat[2][1] = cv[4]; mat[2][2] = cv[5]; res[0] = 0; res[1] = 0; res[2] = 0; for(Int_t i=0;i<3;i++){ for(Int_t j=0;j<3;j++){ res[0] += mat[i][j]*versX[i]*versX[j]; res[1] += mat[i][j]*versY[i]*versY[j]; res[2] += mat[i][j]*versZ[i]*versZ[j]; } } res[0] = TMath::Sqrt(TMath::Abs(res[0]));//cv[0]); res[1] = TMath::Sqrt(TMath::Abs(res[1]));//cv[5]); res[2] = TMath::Sqrt(TMath::Abs(res[2]));//cv[5]); res[0] *= rTOF/rTOFused; res[1] *= rTOF/rTOFused; res[2] *= rTOF/rTOFused; }
int main(int ac, char *av[]) { if(ac > 2) { std::auto_ptr<QCoreApplication> cmd; { for (int i = 1; i < ac; ++i) if (std::string(av[i]) == std::string("--action=cnt") || std::string(av[i]) == std::string("--action=vis")) { cmd.reset(new QApplication(ac, av)); std::cout << "Starting GUI-based command line interface." << std::endl; break; } if(!cmd.get()) cmd.reset(new QCoreApplication(ac, av)); } cmd->setOrganizationName("LabSolver"); cmd->setApplicationName("DSI Studio"); try { std::cout << "DSI Studio " << __DATE__ << ", Fang-Cheng Yeh" << std::endl; // options for general options po::options_description desc("reconstruction options"); desc.add_options() ("help", "help message") ("action", po::value<std::string>(), "rec:diffusion reconstruction trk:fiber tracking") ("source", po::value<std::string>(), "assign the .src or .fib file name") ; po::variables_map vm; po::store(po::command_line_parser(ac, av).options(desc).allow_unregistered().run(),vm); if (vm.count("help")) { std::cout << "example: perform reconstruction" << std::endl; std::cout << " --action=rec --source=test.src.gz --method=4 " << std::endl; std::cout << "example: perform fiber tracking" << std::endl; std::cout << " --action=trk --source=test.src.gz.fib.gz --method=0 --fiber_count=5000" << std::endl; return 1; } if (!vm.count("action") || !vm.count("source")) { std::cout << "invalid command, use --help for more detail" << std::endl; return 1; } if(vm["action"].as<std::string>() == std::string("rec")) return rec(ac,av); if(vm["action"].as<std::string>() == std::string("trk")) return trk(ac,av); if(vm["action"].as<std::string>() == std::string("src")) return src(ac,av); if(vm["action"].as<std::string>() == std::string("ana")) return ana(ac,av); if(vm["action"].as<std::string>() == std::string("exp")) return exp(ac,av); if(vm["action"].as<std::string>() == std::string("atl")) return atl(ac,av); if(vm["action"].as<std::string>() == std::string("cnt")) return cnt(ac,av); if(vm["action"].as<std::string>() == std::string("vis")) return vis(ac,av); std::cout << "invalid command, use --help for more detail" << std::endl; return 1; } catch(const std::exception& e ) { std::cout << e.what() << std::endl; } catch(...) { std::cout << "unknown error occured" << std::endl; } return 1; } QApplication a(ac,av); a.setOrganizationName("LabSolver"); a.setApplicationName("DSI Studio"); QFont font; font.setFamily(QString::fromUtf8("Arial")); a.setFont(font); // load template if(!fa_template_imp.load_from_file()) { QMessageBox::information(0,"Error","Cannot find HCP488_QA.nii.gz in file directory",0); return false; } // load atlas load_atlas(); MainWindow w; w.setFont(font); w.show(); w.setWindowTitle(QString("DSI Studio ") + __DATE__ + " build"); return a.exec(); }
// Compass angle = track in [0,2pi) double Vect2::compassAngle() const { return to_2pi(trk()); }
int cnt_ind(void) { std::shared_ptr<fib_data> handle = cmd_load_fib(po.get("source")); if(!handle.get()) return 1; int normalization = po.get("norm",0); std::cout << "normalization=" << normalization << std::endl; if(!po.has("study")) { std::cout << "Please assign the study FIB file to --study." << std::endl; return 1; } if(!handle->is_qsdr) { std::cout << "Please assign a QSDR reconstructed FIB file to --source." << std::endl; return 1; } connectometry_result cnt_result; if(handle->has_odfs()) { std::cout << "Individual FIB compared with individual FIB." << std::endl; std::shared_ptr<fib_data> temp_handle = cmd_load_fib(po.get("template",fib_template_file_name_2mm)); if(!temp_handle.get()) return 1; if(!cnt_result.individual_vs_individual(temp_handle,po.get("source").c_str(),po.get("study").c_str(),normalization)) goto error; else goto run; } if(handle->db.has_db()) { std::cout << "Connectometry db compared with individual FIB." << std::endl; if(!cnt_result.individual_vs_db(handle,po.get("study").c_str())) goto error; else goto run; } // versus template { std::cout << "Individual FIB compared with a template FIB" << std::endl; if(normalization == 0) normalization = 1; if(!cnt_result.individual_vs_atlas(handle,po.get("study").c_str(),normalization)) goto error; else goto run; } { run: handle->report = handle->db.report + cnt_result.report; trk(handle); return 0; } { error: std::cout << cnt_result.error_msg << std::endl; return 1; } }
void TestZRange(const char *name, const char *lutfile, int extraFlags, int clean_lut, RWeightMode weightMode=RWNone, bool biasMap=false, bool biasCorrect=false) { ImageData lut = ReadLUTFile(lutfile); vector3f delta(0.001f,0.001f, 0.001f); if(PathSeperator(lutfile).extension != "jpg"){ WriteJPEGFile(SPrintf("%s-lut.jpg",name).c_str(), lut); } if (clean_lut) { BenchmarkLUT::CleanupLUT(lut); WriteJPEGFile( std::string(lutfile).substr(0, strlen(lutfile)-4).append("_bmlut.jpg").c_str(), lut ); } QTrkComputedConfig settings; settings.qi_iterations = 2; settings.zlut_minradius = 1; settings.qi_minradius = 1; settings.width = settings.height = 100; settings.Update(); float maxVal=10000; std::vector<float> stdv; dbgprintf("High-res LUT range...\n"); SampleFisherMatrix fm( maxVal); QueuedCPUTracker trk(settings); ImageData rescaledLUT; ResampleLUT(&trk, &lut, lut.h, &rescaledLUT); if (biasCorrect) { CImageData result; trk.ComputeZBiasCorrection(lut.h*10, &result, 4, true); WriteImageAsCSV(SPrintf("%s-biasc.txt", name).c_str(), result.data, result.w, result.h); } int f = 0; if (weightMode == RWDerivative) f |= LT_LocalizeZWeighted; else if(weightMode == RWRadial) { std::vector<float> w(settings.zlut_radialsteps); for (int i=0;i<settings.zlut_radialsteps;i++) w[i]= settings.zlut_minradius + i/(float)settings.zlut_radialsteps*settings.zlut_maxradius; trk.SetRadialWeights(&w[0]); } else if (weightMode == RWStetson) trk.SetRadialWeights( ComputeRadialBinWindow(settings.zlut_radialsteps) ); trk.SetLocalizationMode(LT_QI|LT_LocalizeZ|LT_NormalizeProfile|extraFlags|f); uint nstep= InDebugMode ? 20 : 1000; uint smpPerStep = InDebugMode ? 2 : 200; if (biasMap) { smpPerStep=1; nstep=InDebugMode? 200 : 2000; } std::vector<vector3f> truepos, positions,crlb; std::vector<float> stdevz; for (uint i=0;i<nstep;i++) { float z = 1 + i / (float)nstep * (rescaledLUT.h-2); vector3f pos = vector3f(settings.width/2, settings.height/2, z); truepos.push_back(pos); Matrix3X3 invFisherLUT = fm.Compute(pos, delta, rescaledLUT, settings.width, settings.height, settings.zlut_minradius, settings.zlut_maxradius).Inverse(); crlb.push_back(sqrt(invFisherLUT.diag())); ImageData img=ImageData::alloc(settings.width,settings.height); for (uint j=0;j<smpPerStep; j++) { vector3f rndvec(rand_uniform<float>(), rand_uniform<float>(), rand_uniform<float>()); if (biasMap) rndvec=vector3f(); vector3f rndpos = pos + vector3f(1,1,0.1) * (rndvec-0.5f); // 0.1 plane is still a lot larger than the 0.02 typical accuracy GenerateImageFromLUT(&img, &rescaledLUT, settings.zlut_minradius, settings.zlut_maxradius, rndpos, true); img.normalize(); if (!biasMap) ApplyPoissonNoise(img, maxVal); LocalizationJob job(positions.size(), 0, 0, 0); trk.ScheduleImageData(&img, &job); positions.push_back(rndpos); if(j==0 && InDebugMode) { WriteJPEGFile(SPrintf("%s-sampleimg.jpg",name).c_str(), img); } } dbgprintf("[%d] z=%f Min std deviation: X=%f, Y=%f, Z=%f.\n", i, z, crlb[i].x,crlb[i].y,crlb[i].z); img.free(); } WaitForFinish(&trk, positions.size()); std::vector<vector3f> trkmean(nstep), trkstd(nstep); std::vector<vector3f> resultpos(nstep*smpPerStep); for (uint i=0;i<positions.size();i++) { LocalizationResult lr; trk.FetchResults(&lr, 1); resultpos[lr.job.frame]=lr.pos; } for (uint i=0;i<nstep;i++) { for (uint j=0;j<smpPerStep;j ++) { vector3f err=resultpos[i*smpPerStep+j]-positions[i*smpPerStep+j]; trkmean[i]+=err; } trkmean[i]/=smpPerStep; vector3f variance; for (uint j=0;j<smpPerStep;j ++) { vector3f r = resultpos[i*smpPerStep+j]; vector3f t = positions[i*smpPerStep+j];; vector3f err=r-t; err -= trkmean[i]; variance += err*err; if (InDebugMode) { dbgprintf("Result: x=%f,y=%f,z=%f. True: x=%f,y=%f,z=%f\n", r.x,r.y,r.z,t.x,t.y,t.z); } } if (biasMap) trkstd[i]=vector3f(); else trkstd[i] = sqrt(variance / (smpPerStep-1)); } vector3f mean_std; std::vector<float> output; for(uint i=0;i<nstep;i++) { dbgprintf("trkstd[%d]:%f crlb=%f bias=%f true=%f\n", i, trkstd[i].z, crlb[i].z, trkmean[i].z, truepos[i].z); output.push_back(truepos[i].z); output.push_back(trkmean[i].x); output.push_back(trkstd[i].x); output.push_back(trkmean[i].z); output.push_back(trkstd[i].z); output.push_back(crlb[i].x); output.push_back(crlb[i].z); mean_std += trkstd[i]; } dbgprintf("mean z err: %f\n", (mean_std/nstep).z); WriteImageAsCSV( SPrintf("%s_%d_flags%d_cl%d.txt",name, weightMode, extraFlags,clean_lut).c_str(), &output[0], 7, output.size()/7); lut.free(); rescaledLUT.free(); }