1 #include "../cputrack/std_incl.h" 2 #include "../cputrack/cpu_tracker.h" 3 #include "../cputrack/random_distr.h" 4 #include "../cputrack/QueuedCPUTracker.h" 5 #include "../cputrack/FisherMatrix.h" 6 #include "../cputrack/BeadFinder.h" 7 #include "../cputrack/LsqQuadraticFit.h" 8 #include "../utils/ExtractBeadImages.h" 9 #include "../cputrack/BenchmarkLUT.h" 10 #include "../cputrack/CubicBSpline.h" 43 int qi_iterations = 7;
44 int xcor_iterations = 7;
47 int radialSteps = 64, zplanes = 120;
48 float zmin = 2, zmax = 8;
49 float zradius = tracker->
xcorw/2;
51 float* zlut =
new float[radialSteps*zplanes];
52 for (
int x=0;x<zplanes;x++) {
54 float s = zmin + (zmax-zmin) * x/(
float)(zplanes-1);
59 tracker->
SetRadialZLUT(zlut, zplanes, radialSteps, 1,1, zradius,
true,
true);
66 double tcom = 0.0, tgen=0.0, tz = 0.0, tqi=0.0, txcor=0.0;
70 float xp = tracker->
GetWidth()/2+(rand_uniform<float>() - 0.5) * 5;
71 float yp = tracker->
GetHeight()/2+(rand_uniform<float>() - 0.5) * 5;
72 float z = zmin + 0.1f + (zmax-zmin-0.2f) * rand_uniform<float>();
80 bool boundaryHit =
false;
85 comdist.
x += fabsf(com.
x - xp);
86 comdist.
y += fabsf(com.
y - yp);
88 xcordist.
x +=fabsf(xcor.
x - xp);
89 xcordist.
y +=fabsf(xcor.
y - yp);
93 qidist.
x += fabsf(qi.
x - xp);
94 qidist.
y += fabsf(qi.
y - yp);
100 float est_z = zmin + (zmax-zmin)*tracker->
ComputeZ(qi, 64, 0, &boundaryHit, 0) / (zplanes-1);
101 zdist += fabsf(est_z-z);
118 dbgprintf(
"Image gen. (img/s): %f\nCenter-of-Mass speed (img/s): %f\n", Nns/tgen, Nns/tcom);
119 dbgprintf(
"XCor estimation (img*it/s): %f\n", (Nns*xcor_iterations)/txcor);
120 dbgprintf(
"COM+XCor(%d) (img/s): %f\n", xcor_iterations, Nns/(tcom+txcor));
121 dbgprintf(
"Z estimation (img/s): %f\n", Nns/tz);
122 dbgprintf(
"QI speed: %f (img*it/s)\n", (Nns*qi_iterations)/tqi);
123 dbgprintf(
"Average dist: COM x: %f, y: %f\n", comdist.
x/N, comdist.
y/N);
124 dbgprintf(
"Average dist: Cross-correlation x: %f, y: %f\n", xcordist.
x/N, xcordist.
y/N);
125 dbgprintf(
"Average dist: QI x: %f, y: %f\n", qidist.
x/N, qidist.
y/N);
126 dbgprintf(
"Average dist: Z: %f. Mean error:%f\n", zdist/N, zerrsum/N);
141 bool boundaryHit =
false;
145 assert(xcor.
x == 15.0f && xcor.
y == 15.0f);
160 bool boundaryHit =
false;
167 for (
int i=0;i<I;i++) {
170 dbgprintf(
"qi[%d]. New=%.4f, %.4f;\tOld=%.4f, %.4f\n", i, np.
x, np.
y, pos.
x, pos.
y);
183 for (
int i=0;i<10;i++) {
184 float xp = tracker->
GetWidth()/2+(rand_uniform<float>() - 0.5) * 20;
185 float yp = tracker->
GetHeight()/2+(rand_uniform<float>() - 0.5) * 20;
195 dbgprintf(
"XCor: %f,%f. Err: %d\n", xcor.
x-xp, xcor.
y-yp, boundaryHit);
199 dbgprintf(
"QI: %f,%f. Err: %d\n", qi.
x-xp, qi.
y-yp, boundaryHit);
210 for (
int i=0;i<10;i++) {
211 float xp = tracker->
GetWidth()/2+(rand_uniform<float>() - 0.5) * 20;
212 float yp = tracker->
GetHeight()/2+(rand_uniform<float>() - 0.5) * 20;
222 dbgprintf(
"XCor: %f,%f. Err: %d\n", xcor.
x-xp, xcor.
y-yp, boundaryHit);
226 dbgprintf(
"QI: %f,%f. Err: %d\n", qi.
x-xp, qi.
y-yp, boundaryHit);
239 for (
int x=0;x<N;x++) {
240 float xpos = X + 2.0f * x / (float)N;
247 bool boundaryHit =
false;
250 dbgprintf(
"xpos:%f, COM err: %f, XCorInterp err: %f. QI err: %f\n", xpos, com.
x-xpos, xcorInterp.
x-xpos, qipos.
x-xpos);
259 char* data=
new char[W*H];
260 FILE* f=fopen(
"singlebead.bin",
"rb");
261 fread(data,1,80*80,f);
266 float step=testrange/steps;
276 float *xcorErrMap =
new float[steps*steps];
277 float *qiErrMap =
new float[steps*steps];
279 for (
int y=0;y<steps;y++){
280 for (
int x=0;x<steps;x++)
282 vector2f initial (cmp.
x+step*(x-steps/2), cmp.
y+step*(y-steps/2) );
286 errXCor.
x += fabs(xcor.
x-cmp.
x);
287 errXCor.
y += fabs(xcor.
y-cmp.
y);
288 xcorErrMap[y*steps+x] =
distance(xcor,cmp);
290 errQI.
x += fabs(qi.
x-cmp.
x);
291 errQI.
y += fabs(qi.
y-cmp.
y);
292 qiErrMap[y*steps+x] =
distance(qi,cmp);
309 float* img =
new float[w*h];
310 const char* lutname =
"LUTexample25X.jpg";
315 ReadJPEGFile(&lutdata[0], lutdata.size(), &lut, &lutw, &luth);
322 const char* imgname =
"SingleBead.jpg";
331 dbgprintf(
"%s: COM: %f, %f. QI: %f, %f\n", imgname, com.
x, com.
y, qi.
x, qi.
y);
333 std::vector<float> angularProfile(128);
334 float asym = trk.
ComputeAsymmetry(qi, 64, angularProfile.size(), 1, 30, &angularProfile[0]);
336 WriteImageAsCSV(
"angprof.csv", &angularProfile[0], angularProfile.size(), 1);
337 dbgprintf(
"Asymmetry value: %f\n", asym);
338 std::vector<float> crp(128);
339 float* crpmap =
new float[angularProfile.size()*crp.size()];
340 ComputeCRP(&crp[0], crp.size(), angularProfile.size(), 1, 30, qi, &img, 0.0f);
341 WriteImageAsCSV(
"crpmap.csv", crpmap, crp.size(), angularProfile.size());
358 const int radialsteps=64;
359 float radprof[radialsteps];
367 std::vector<float> wnd(rsteps);
368 for(
int x=0;x<rsteps;x++)
369 wnd[x]=
Lerp(minRadius, maxRadius, x/(
float)rsteps) / (0.5f * (minRadius+maxRadius));
386 for (
int i=0;i<10;i++) {
390 dbgprintf(
"Noise level std: %f\n",stdev);
404 float z = trk.
ComputeZ(qi,3*img.
w, 0, 0, 0, 0,
false);
405 float znorm = trk.
ComputeZ(qi,3*img.
w, 0, 0, 0, 0,
true);
407 dbgprintf(
"Z: %f, ZNorm: %f, true:%f\n", z, znorm, pos.
z);
428 std::vector< vector2f> results (N);
429 for (
int i=0;i<N;i++) {
440 results[i].x = pos.
z;
441 results[i].y = z-pos.
z;
452 void TestZRange(
const char *name,
const char *lutfile,
int extraFlags,
int clean_lut,
RWeightMode weightMode=
RWNone,
bool biasMap=
false,
bool biasCorrect=
false)
455 vector3f delta(0.001f,0.001f, 0.001f);
463 WriteJPEGFile( std::string(lutfile).substr(0, strlen(lutfile)-4).append(
"_bmlut.jpg").c_str(), lut );
474 std::vector<float> stdv;
510 std::vector<vector3f> truepos, positions,crlb;
511 std::vector<float> stdevz;
512 for (
uint i=0;i<nstep;i++)
514 float z = 1 + i / (float)nstep * (rescaledLUT.
h-2);
516 truepos.push_back(pos);
518 crlb.push_back(
sqrt(invFisherLUT.
diag()));
522 for (
uint j=0;j<smpPerStep; j++) {
523 vector3f rndvec(rand_uniform<float>(), rand_uniform<float>(), rand_uniform<float>());
531 positions.push_back(rndpos);
536 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);
540 std::vector<vector3f> trkmean(nstep), trkstd(nstep);
541 std::vector<vector3f> resultpos(nstep*smpPerStep);
542 for (
uint i=0;i<positions.size();i++) {
547 for (
uint i=0;i<nstep;i++) {
548 for (
uint j=0;j<smpPerStep;j ++) {
549 vector3f err=resultpos[i*smpPerStep+j]-positions[i*smpPerStep+j];
552 trkmean[i]/=smpPerStep;
554 for (
uint j=0;j<smpPerStep;j ++) {
555 vector3f r = resultpos[i*smpPerStep+j];
556 vector3f t = positions[i*smpPerStep+j];;
562 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);
566 else trkstd[i] =
sqrt(variance / (smpPerStep-1));
570 std::vector<float> output;
571 for(
uint i=0;i<nstep;i++) {
572 dbgprintf(
"trkstd[%d]:%f crlb=%f bias=%f true=%f\n", i, trkstd[i].z, crlb[i].z, trkmean[i].z, truepos[i].z);
573 output.push_back(truepos[i].z);
574 output.push_back(trkmean[i].x);
575 output.push_back(trkstd[i].x);
576 output.push_back(trkmean[i].z);
577 output.push_back(trkstd[i].z);
578 output.push_back(crlb[i].x);
579 output.push_back(crlb[i].z);
581 mean_std += trkstd[i];
583 dbgprintf(
"mean z err: %f\n", (mean_std/nstep).z);
584 WriteImageAsCSV(
SPrintf(
"%s_%d_flags%d_cl%d.txt",name, weightMode, extraFlags,clean_lut).c_str(), &output[0], 7, output.size()/7);
600 for (
uint i=0;i<results.size();i++) {
601 dbgprintf(
"beadpos: x=%d, y=%d\n", results[i].x, results[i].y);
602 img.at(results[i].x+cfg.
roi/2, results[i].y+cfg.
roi/2) = 1.0f;
604 dbgprintf(
"%d beads total\n", results.size());
626 auto resultsZA = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qi-fourierlut", locMode, 200, NF,zpos);
629 auto resultsQI = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qi", locModeQI, 200, NF, zpos);
631 resultsZA.computeStats();
632 resultsQI.computeStats();
634 dbgprintf(
"FourierLUT: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsZA.meanErr.x, resultsZA.stdev.x, resultsZA.meanErr.z, resultsZA.stdev.z);
635 dbgprintf(
"Only QI: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsQI.meanErr.x, resultsQI.stdev.x, resultsQI.meanErr.z, resultsQI.stdev.z);
640 const char*basepath=
"D:/jcnossen1/datasets/RefBeads 2013-09-02/2013-09-02/";
642 process_bead_dir(
SPrintf(
"%s/%s", basepath,
"tmp_001").c_str(), 80, [&] (
ImageData *img,
int bead,
int frame) {
660 auto resultsQI = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qi", locModeQI, 200, NF);
663 auto resultsZA = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qi-zlutalign", locMode, 200, NF );
665 resultsZA.computeStats();
666 resultsQI.computeStats();
668 dbgprintf(
"ZLUTAlign: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsZA.meanErr.x, resultsZA.stdev.x, resultsZA.meanErr.z, resultsZA.stdev.z);
669 dbgprintf(
"Only QI: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsQI.meanErr.x, resultsQI.stdev.x, resultsQI.meanErr.z, resultsQI.stdev.z);
691 auto resultsQI = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qa", locModeQI, N, NF);
694 auto resultsZA = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qa-qalign", locMode, N, NF );
696 resultsZA.computeStats();
697 resultsQI.computeStats();
699 dbgprintf(
"QuadrantAlign: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsZA.meanErr.x, resultsZA.stdev.x, resultsZA.meanErr.z, resultsZA.stdev.z);
700 dbgprintf(
"Only QI: X= %f. stdev: %f\tZ=%f, stdev: %f\n", resultsQI.meanErr.x, resultsQI.stdev.x, resultsQI.meanErr.z, resultsQI.stdev.z);
710 auto results = RunTracker<QueuedCPUTracker> (
"lut000.jpg", &cfg,
false,
"qi", locModeQI, 1000, 10000/255 );
712 results.computeStats();
713 dbgprintf(
"X= %f. stdev: %f\tZ=%f, stdev: %f\n",
714 results.meanErr.x, results.stdev.x, results.meanErr.z, results.stdev.z);
722 for (
int i=0;i<N;i++)
723 v[i] = -
sqrt(1+(i-maxpos)*(i-maxpos));
725 dbgprintf(
"Max: %f, true: %f\n", max, maxpos);
745 for (
int z=0;z<6;z++) {
770 std::vector<vector3f> results, truepos;
773 std::vector<ImageData> imgs(NImg);
781 for (
int i=0;i<NImg;i++) {
783 vector3f pos = centerpos + range*
vector3f(rand_uniform<float>()-0.5f, rand_uniform<float>()-0.5f, rand_uniform<float>()-0.5f)*1;
795 truepos.push_back(pos);
800 for (
uint i=0;i<results.size();i++) {
806 for (
int i=0;i<NImg;i++)
810 r.
Compute(results, [&](
int index) {
return truepos[index]; });
817 void ScatterBiasArea(
int roi,
float scan_width,
int steps,
int samples,
int qi_it,
float angstep)
819 std::vector<float> u=
linspace(roi/2-scan_width/2,roi/2+scan_width/2, steps);
842 vector3f ct(roi/2,roi/2,lut.
h/2 + 0.123f);
843 float dx = scan_width/steps;
853 std::string fn =
SPrintf(
"sb_area_roi%d_scan%d_steps%d_qit%d_N%d", roi, (
int)scan_width, steps, qi_it, samples);
858 for (
int y=0;y<steps;y++) {
859 for (
int x=0;x<steps;x++)
861 vector3f cpos( (x+0.5f-steps/2) * dx, (y+0.5f-steps/2) * dx, 0 );
866 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 };
884 sprintf(buf,
"%f %f %f",com.
x,com.
y,t);
889 bool boundaryHit =
false;
890 for(
int qi_iterations = 1; qi_iterations < 10; qi_iterations++){
895 sprintf(buf,
"%f %f %f",qi.
x,qi.
y,t);
902 int size = img.
w * 2 + img.
h * 2 - 4;
903 float* outeredge =
new float[size];
905 float* max = std::max_element(img.
data,img.
data+(img.
w*img.
h));
906 float* min = std::min_element(img.
data,img.
data+(img.
w*img.
h));
907 float* outer_max = std::max_element(outeredge,outeredge+size);
908 float* outer_min = std::min_element(outeredge,outeredge+size);
910 float out = (*outer_max-*outer_min)/(*max-*min);
917 for(
uint ii = 0; ii < beads.size(); ii++){
919 output->
newFile(
SPrintf(
"%d,%d-ROI-%d",beads.at(ii).x,beads.at(ii).y,ROISize));
921 for(
int x_i = -maxdisplacement; x_i <= maxdisplacement; x_i++){
922 for(
int y_i = -maxdisplacement; y_i <= maxdisplacement; y_i++){
923 int x = beads.at(ii).x + x_i - ROISize/2;
924 int y = beads.at(ii).y + y_i - ROISize/2;
926 output->
outputImage(img,
SPrintf(
"%d,%d-Crop",beads.at(ii).x + x_i, beads.at(ii).y + y_i));
927 output->
outputString(
SPrintf(
"%d,%d - ROI (%d,%d) -> (%d,%d)",x_i,y_i,x,y,x+ROISize,y+ROISize));
940 for(
uint ii = 0; ii < beads.size(); ii++){
941 output->
newFile(
SPrintf(
"%d,%d-Inter",beads.at(ii).x,beads.at(ii).y));
943 int x = beads.at(ii).x - ROISize/2;
944 int y = beads.at(ii).y - ROISize/2;
958 for(
uint ii = 0; ii < beads.size(); ii++){
959 output->
newFile(
SPrintf(
"%d,%d-Skew",beads.at(ii).x,beads.at(ii).y));
961 int x = beads.at(ii).x - ROISize/2;
962 int y = beads.at(ii).y - ROISize/2;
980 out =
"Beads-Background";
983 for(
uint ii = 0; ii < beads.size(); ii++){
984 int x = beads.at(ii).x - ROISize/2;
985 int y = beads.at(ii).y - ROISize/2;
1000 std::vector<BeadPos> beads = read_beadlist(
SPrintf(
"%sbeadlist.txt",folder.c_str()));
1003 int numImgInStack = 1218;
1004 int numPositions = 1001;
1005 float range = 10.0f;
1006 float umPerImg = range/numImgInStack;
1036 int pxPerBead = ROISize*ROISize;
1037 int memSizePerBead = pxPerBead*
sizeof(float);
1038 int startFrame = 400;
1039 for(
int plane = 0; plane < zplanes; plane++){
1041 int frameNum = startFrame+(int)(numImgInStack-startFrame)*((float)plane/zplanes);
1042 std::string file =
SPrintf(
"%s\img%05d.jpg",folder.c_str(),frameNum);
1046 float* data =
new float[beads.size()*pxPerBead];
1048 for(
uint ii = 0; ii < beads.size(); ii++){
1050 pos.
x = beads.at(ii).x - ROISize/2;
1051 pos.
y = beads.at(ii).y - ROISize/2;
1054 memcpy(data+ii*pxPerBead,crop.
data,memSizePerBead);
1074 for(
int ii = 0; ii < beads.size(); ii++){
1089 std::vector<BeadPos> beads = read_beadlist(
SPrintf(
"%sbeadlist.txt",imagePath.c_str()));
1091 if(beads.size() == 0){
1149 std::string file =
SPrintf(
"%s\lut%03d.jpg",zlutPath.c_str(),0);
1153 output->
outputString(
"ZLUT settings do not match LUT image sizes!",
true);
1158 int zplanes = lut.h;
1162 float* zluts =
new float[zplanes*res*beads.size()];
1164 for(
int ii = 0; ii < beads.size(); ii++){
1165 std::string file =
SPrintf(
"%s\lut%03d.jpg",zlutPath.c_str(),ii);
1167 memcpy(zluts+ii*res*zplanes,lut.data,res*zplanes*
sizeof(
float));
1171 positions[ii].
x = beads.at(ii).x - ROISize/2;
1172 positions[ii].
y = beads.at(ii).y - ROISize/2;
1198 std::vector<std::string> colnames;
1200 colnames.push_back(
SPrintf(
"%d",ii));
1205 SPrintf(
"%s\\RMFrameInfo.txt",output->
folder.c_str()).c_str(),
1210 int numFramesToTrack =
NumJpgInDir(imagePath +
"*");
1211 for(
int ii = 0; ii < numFramesToTrack; ii++){
1212 std::string file =
SPrintf(
"%s\img%05d.jpg",imagePath.c_str(),ii);
1216 int queued = qtrk->
ScheduleFrame(img.data,
sizeof(
float)*img.w,img.w,img.h,positions,beads.size(),
QTrkFloat,&job);
1277 std::vector<BeadPos> beads = read_beadlist(
"D:\\TestImages\\beadlist.txt");
1278 output->
newFile(
"TestInfo",
"a");
1282 else if(test ==
Inter)
1284 else if(test ==
Skew)
1286 else if(test ==
Backg)
1288 output->
outputString(
SPrintf(
"Image %s\nBeadlist D:\\TestImages\\beadlist.txt\nNumBeads %d\nROISize %d",image,beads.size(),ROISize));
1300 TestSkew(beads,source,output,ROISize);
1308 output->
newFile(
"TestInfo",
"a");
1316 float displacement = 0;
1317 float skewFact = 0.0f;
1326 printf_s(
"Current settings: image %s\nROI %d, skewFact %f, displacement %f, bgCorr %f\n\n", (imgSel == 0)?
"generated":
"CroppedBead.jpg", ROISize, skewFact, displacement, bgCorr);
1327 std::cout <<
"What setting to change? (? for list, 0 to run)\n";
1328 std::cin >> selChar;
1331 printf(
"i: imgSel (0: Generated, 1: CroppedBead.jpg)\nr: ROISize\nb: COM Background correction\n");
1332 printf(
"\nOnly for generated image:\n\ts: skewFact\n\td: displacement\n");
1338 std::cin >> ROISize;
1341 std::cin >> skewFact;
1344 std::cin >> displacement;
1352 std::cout << std::endl;
1353 }
while(selChar !=
'0');
1363 GenerateTestImage(imgRaw,(
float)ROISize/2+displacement,(
float)ROISize/2+displacement,5,0);
1397 printf(
"q: %d\n",queued);
1417 std::cout <<
"\nContinue?\n";
1419 }
while(inChar !=
'0');
1446 output->
outputString(
"Select test or ? for menu:",
true);
1447 std::string imagesPath, LUTPath;
1471 BuildZLUT(
"D:\\TestImages\\TestMovie150507_2\\images\\jpg\\Zstack\\",output);
1488 RunZTrace(
"C:\\TestImages\\TestMovie150507_2\\images\\jpg\\Zstack\\",
"C:\\TestImages\\TestMovie150507_2\\ZLUTS_50planes\\",output);
1496 std::cin >> ROISize;
1504 }
while(inChar !=
'0');
void WriteArrayAsCSVRow(const char *file, float *d, int len, bool append)
virtual int GetResultCount()=0
Get the number of finished localization jobs (=results) available in memory.
float zlut_minradius
Distance in pixels from the bead center from which to start sampling profiles. Default 1...
static void TestBSplineMax(float maxpos)
void BuildConvergenceMap(int iterations)
virtual int ScheduleFrame(void *imgptr, int pitch, int width, int height, ROIPosition *positions, int numROI, QTRK_PixelDataType pdt, const LocalizationJob *jobInfo)
Schedule an entire frame at once, allowing for further optimizations.
float BackgroundRMS(ImageData img)
std::vector< float > ComputeRadialWeights(int rsteps, float minRadius, float maxRadius)
void GetOuterEdges(float *out, int size, ImageData img)
int localizationsDone
Amount of localizations finished by the linked QueuedTracker instance.
void GenerateTestImage(ImageData &img, float xp, float yp, float size, float SNratio)
int numBeads
Number of beads for which to grab results. Should always equal the amount of beads in a single frame...
static double WaitForFinish(QueuedTracker *qtrk, int N)
void ComputeRadialProfile(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, bool crp, bool *boundaryHit=0, bool normalize=true)
Wrapper to compute a radial profile.
TImageData< float > ImageData
void FinalizeLUT() override
Finalize the lookup tables in memory.
void Compute(const std::vector< vector3f > &results, std::function< vector3f(int x) > truepos)
int NumJpgInDir(const std::string &dirName_in)
void dbgout(const std::string &s)
void outputImage(ImageData img, std::string filename="UsedImage")
float qi_minradius
Distance in pixels from the bead center from which to start sampling profiles. Default 1...
int width
Width of regions of interest to be handled. Typically equals height (square ROI). ...
vector3f scaling
Scaling factor for each of the three dimensions.
uint maxFramesInMemory
Number of frames for which to keep the data in memory. 0 for infinite.
int processedFrames
Number of frames processed by the ResultManager.
void RunTest(Tests test, const char *image, outputter *output, int ROISize)
static void CleanupLUT(ImageData &lut)
void outputString(std::string out, bool ConsoleOnly=false)
void ResampleLUT(T *qtrk, ImageData *lut, int zplanes, ImageData *newlut, const char *jpgfile=0, uint buildLUTFlags=0)
void PixelationErrorTest()
Struct used to define the top-left corner position of an ROI within a frame. ROI is [ x ...
Class with all CPU algorithm implementations.
ImageData ReadLUTFile(const char *lutfile)
void GenerateZLUTFittingCurve(const char *lutfile)
void Flush() override
Stop waiting for more jobs to do, and just process the current batch.
vector3f offset
Offset value for each of the three dimensions.
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
void WriteJPEGFile(uchar *data, int w, int h, const char *filename, int quality)
bool testRun
Flag to run a test run.
ImageData AddImages(ImageData img1, ImageData img2, vector2f displacement)
int FetchResults(LocalizationResult *dstResult, int maxResults) override
Fetch available results.
float distance(vector2f a, vector2f b)
void BeginLUT(uint flags)
Setup to begin building a lookup table.
Structure for job results.
void BuildZLUT(std::string folder, outputter *output)
int height
Height of regions of interest to be handled. Typically equals width (square ROI). ...
int GetResultCount() override
Get the number of finished localization jobs (=results) available in memory.
vector2< float > vector2f
void ClearResults() override
Clear results.
Structure for the settings used by the algorithms implemented in QueuedTracker.
float LUTProfileCompare(float *profile, int zlutIndex, float *cmpProf, LUTProfileMaxComputeMode maxPosMethod, float *fitcurve=0, int *maxPos=0, int frameNum=0)
Compare a profile to a LUT and calculate the optimum Z value for it.
int zlut_radialsteps
Number of radial steps to sample on.
vector3< T > sqrt(const vector3< T > &a)
void RescaleLUT(CPUTracker *trk, ImageData *lut)
std::vector< Position > Find(ImageData *img, float *sample, Config *cfg)
void SetImage8Bit(uchar *srcImage, uint srcpitch)
Set an image with 8 bit type.
float imageMean
Average pixel value of the ROI.
Class that handles data gathering and saving from QueuedTracker instances.
Structure to keep track of frame counts.
virtual void SetLocalizationMode(LocMode_t locType)=0
Select which algorithm is to be used.
uint frame
Frame number this ROI belongs to.
int numFrameInfoColumns
Number of columns in the frame info metadata file. Additional columns can be added to save more data ...
static TImageData alloc(int w, int h)
float SkewParam(ImageData img)
float & GetPixel(int x, int y)
Get the image pixel greyscale value at point (x,y).
T Lerp(T a, T b, float x)
void TestROIDisplacement(std::vector< BeadPos > beads, ImageData oriImg, outputter *output, int ROISize, int maxdisplacement=0)
vector2f ComputeMeanAndCOM(float bgcorrection=0.0f)
Calculate the center of mass of the image.
std::vector< uchar > ReadToByteBuffer(const char *filename)
std::vector< float > ComputeRadialBinWindow(int rsteps)
Calculate the radial weights for ZLUT profile comparisons.
Matrix3X3 Inverse() const
int lostFrames
Number of frames deleted from memory before results were finished and/or saved.
void Update()
Compute the derived settings.
void TestZRange(const char *name, const char *lutfile, int extraFlags, int clean_lut, RWeightMode weightMode=RWNone, bool biasMap=false, bool biasCorrect=false)
float * srcImage
Memory region that holds the image on which tracking is to be performed.
Make a fourier based lookup table.
vector3f pos
Final 3D position found. If no z localization was performed, the value of z will be 0...
int xcorw
Cross correlation profile length.
void TestZRangeBias(const char *name, const char *lutfile, bool normProf)
float com_bgcorrection
Background correction factor for COM. Defines the number of standard deviations data needs to be away...
void TestInterference(std::vector< BeadPos > beads, ImageData oriImg, outputter *output, int ROISize, vector2f displacement=vector2f(60, 0))
void CorrectedRadialProfileTest()
float mean
Mean intensity of the ROI. Calculated in ComputeMeanAndCOM.
ImageData CropImage(ImageData img, int x, int y, int w, int h)
float qi_maxradius
Max radius in pixels of the sampling circle.
Normalize found radial profiles.
void SetRadialZLUT(float *data, int num_zluts, int planes) override
Set the radial lookup tables to be used for z tracking.
float * GetZLUTByIndex(int index)
Get a pointer to the starting pixel of the specified LUT.
float BackgroundMedian(ImageData img)
float ComputeZ(vector2f center, int angularSteps, int zlutIndex, bool *boundaryHit=0, float *profile=0, float *cmpprof=0, bool normalizeProfile=true)
Helper function to calculate the Z position.
virtual void ScheduleLocalization(void *data, int pitch, QTRK_PixelDataType pdt, const LocalizationJob *jobInfo)=0
Add a job to the queue to be processed. A job entails running the required algorithms on a single reg...
LocalizationJob job
Job metadata. See LocalizationJob.
CPU implementation of the QueuedTracker interface.
Structure for settings used by ResultManager.
QTrkComputedConfig cfg
The settings used by this instance of QueuedTracker.
std::vector< T > linspace(T a, T b, int N)
void SetTracker(QueuedTracker *qtrk)
Set the tracker from which to fetch results.
void SetLocalizationMode(LocMode_t lt) override
Select which algorithm is to be used.
int ReadJPEGFile(uchar *srcbuf, int srclen, uchar **data, int *width, int *height)
float zlut_roi_coverage
Factor of the ROI to include in sampling. Between 0 and 1, default 1. Maxradius = ROI/2*roi_coverage...
vector2f ComputeXCorInterpolated(vector2f initial, int iterations, int profileWidth, bool &boundaryHit)
Compute the cross correlation offsets and resulting position.
void SelectTests(const char *image, int OutputMode)
int GetWidth()
Get the width of the image.
void SetRadialZLUT(float *data, int planes, int res, int num_zluts, float minradius, float maxradius, bool copyMemory, bool useCorrelation)
Tell the tracker where in memory the LUT is located.
int capturedFrames
Number of frames captured. Counted through calls to StoreFrameInfo.
#define ALLOCA_ARRAY(T, N)
void Flush()
Write all available data regardless of ResultManagerConfig::writeInterval.
float qi_radial_coverage
Sampling points per radial pixel. Default 3.0.
Structure for derived settings computed from base settings in QTrkSettings.
float zlut_angular_coverage
Factor of the sampling perimeter to cover with angular sampling steps. Between 0 and 1...
FrameCounters GetFrameCounters()
Returns a FrameCounters structure with the current counts.
void SetRadialWeights(float *rweights) override
Set radial weights used for comparing LUT profiles.
Default. Use a 7-point quadratic fit around the error curve's maximum.
void BuildLUT(void *data, int pitch, QTRK_PixelDataType pdt, int plane, vector2f *known_pos=0) override
Add a new lookup table plane.
static SpeedAccResult AccBiasTest(ImageData &lut, QueuedTracker *trk, int N, vector3f centerpos, vector3f range, const char *name, int MaxPixelValue, int extraFlags=0)
int GetHeight()
Get the height of the image.
vector2f firstGuess
(x,y) position found by the COM localization. Used as initial position for the subsequent algorithms...
void PrintMenu(outputter *output)
float qi_roi_coverage
Factor of the ROI to include in sampling. Between 0 and 1, default 1. Maxradius = ROI/2*roi_coverage...
vector3< float > vector3f
void dbgprintf(const char *fmt,...)
float CUDA_SUPPORTED_FUNC ComputeSplineFitMaxPos(T *data, int len)
int qi_iterations
Number of times to run the QI algorithm, sampling around the last found position. ...
void TestBackground(std::vector< BeadPos > beads, ImageData oriImg, outputter *output, int ROISize)
void ComputeCRP(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float paddingValue, float *crpmap)
void ScatterBiasArea(int roi, float scan_width, int steps, int samples, int qi_it, float angstep)
int xc1_iterations
Number of times to run the cross correlation algorithm.
int writeInterval
Interval of number of gathered frames at which to write the data.
float qi_angstep_factor
Factor to reduce angular steps on lower iterations. Default 1.0 (no effect).
void FloatToJPEGFile(const char *name, const float *d, int w, int h)
void CRP_TestGeneratedData()
void ComputeRadialProfile(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float mean, bool normalize)
void ComputeZBiasCorrection(int bias_planes, CImageData *result, int smpPerPixel, bool useSplineInterp)
int GetQueueLength(int *maxQueueLength=0) override
Get the lengths of the queue of jobs to be handled.
uint8_t binaryOutput
Flag (boolean) to output a binary file instead of a text file.
T StdDeviation(T *start, T *end)
void RunZTrace(std::string imagePath, std::string zlutPath, outputter *output)
int xc1_profileWidth
Profile width for the cross correlation.
void newFile(std::string filename, const char *mode="a")
ImageData SkewImage(ImageData img, float fact)
virtual int FetchResults(LocalizationResult *results, int maxResults)=0
Fetch available results.
void WriteToFile()
Write all settings to specified output file (Jordi, to combine with QTrkSettings.testRun) ...
float BackgroundStdDev(ImageData img)
float * GetDebugImage()
Get the debug image.
void RunCOMAndQI(ImageData img, outputter *output)
void WriteImageAsCSV(const char *file, float *d, int w, int h, const char *labels[])
Abstract tracker interface, implemented by QueuedCUDATracker and QueuedCPUTracker.
void ScheduleImageData(ImageData *data, const LocalizationJob *jobInfo)
Quick function to schedule a single ROI from an ImageData object.
void TestSkew(std::vector< BeadPos > beads, ImageData oriImg, outputter *output, int ROISize)
Matrix3X3 Compute(vector3f pos, vector3f delta, ImageData &lut, int w, int h, float zlutMinRadius, float zlutMaxRadius)
int numThreads
Number of threads/streams to use. Defaults differ between CPU and GPU implementations.
vector2f ComputeQI(vector2f initial, int iterations, int radialSteps, int angularStepsPerQuadrant, float angStepIterationFactor, float minRadius, float maxRadius, bool &boundaryHit, float *radialweights=0)
Execute the quadrant interpolation algorithm.
float zlut_radial_coverage
Sampling points per radial pixel. Default 3.0.
float qi_angular_coverage
Factor of the sampling perimeter to cover with angular sampling steps. Between 0 and 1...
float ComputeAsymmetry(vector2f center, int radialSteps, int angularSteps, float minRadius, float maxRadius, float *dstAngProf=0)
Find a measure for the asymmetry of the ROI.
Structure for region of interest metadata.
int xc1_profileLength
Profile length for the cross correlation.
int zlut_angularsteps
Number of angular steps to sample on.
float zlut_maxradius
Max radius in pixels of the sampling circle.
void WriteRadialProf(const char *file, ImageData &d)
void TestFourierLUTOnDataset()
void SetImageFloat(float *srcImage)
Set an image with float type.
std::string SPrintf(const char *fmt,...)
Do a ZLUT lookup with adjusted weights, for testing purposes.
void NormalizeZLUT(float *zlut, int numBeads, int planes, int radialsteps)
void ApplyPoissonNoise(ImageData &img, float poissonMax, float maxval)