QTrk
utils.cpp
Go to the documentation of this file.
1 #include "std_incl.h"
2 #include <cstdarg>
3 #include <functional>
4 #include "utils.h"
5 #include <Windows.h>
6 #undef min
7 #undef max
8 #include <string>
9 #include <complex>
10 
11 #include "random_distr.h"
12 #include "LsqQuadraticFit.h"
13 #include "QueuedTracker.h"
14 #include "threads.h"
15 #include "CubicBSpline.h"
16 #include "time.h"
17 #include <tchar.h>
18 
19 std::string GetCurrentOutputPath(bool ext)
20 {
21  std::string base = "D:\\TestImages\\TestOutput\\";
22  std::string search = base + "*";
23  LPCSTR w_folder = _T(search.c_str());
24 
25  WIN32_FIND_DATA FindFileData;
26  HANDLE hFind;
27 
28  hFind = FindFirstFile(w_folder,&FindFileData);
29  std::string dirName;
30  while(FindNextFile(hFind,&FindFileData))
31  dirName = FindFileData.cFileName;
32  if(ext)
33  return SPrintf("%s%s\\%s",base.c_str(),dirName.c_str(),"ZLUTDiag\\");
34  else
35  return SPrintf("%s%s",base.c_str(),dirName.c_str());
36 }
37 
38 void GetFormattedTimeString(char* output)
39 {
40  time_t rawtime;
41  struct tm * timeinfo;
42  time(&rawtime);
43  timeinfo = localtime(&rawtime);
44  sprintf(output, "%02d%02d%02d-%02d%02d%02d",timeinfo->tm_year-100,timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec);
45 }
46 
47 static std::string logFilename;
48 
49 void dbgsetlogfile(const char*path)
50 {
51  logFilename = path;
52 }
53 
55 {
56 #ifdef WIN32
57  char path[256];
58  HMODULE hm = NULL;
59 
60  GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
61  (LPCSTR) &GetLocalModuleFilename, &hm);
62 
63  GetModuleFileNameA(hm, path, sizeof(path));
64  return path;
65 #else
66  #error GetLocalModuleName() not implemented for this platform
67 #endif
68 }
69 
70 PathSeperator::PathSeperator(std::string fullpath)
71 {
72  int filenameEnd = fullpath.size();
73  int filenameStart = 0;
74  for (int i = fullpath.size()-1; i>=0; i--) {
75  if (fullpath[i] == '.' && extension.empty()) {
76  extension = fullpath.substr(i+1);
77  filenameEnd = i;
78  }
79  if (fullpath[i] == '/' || fullpath[i] == '\\') {
80  directory = fullpath.substr(0,i+1);
81  filenameStart = i+1;
82  break;
83  }
84  }
85  filename = fullpath.substr(filenameStart, filenameEnd - filenameStart);
86 }
87 
88 void WriteToLog(const char *str)
89 {
90  if (logFilename.empty()) {
92  logFilename = ps.directory + ps.filename + "-log.txt";
93  }
94 
95  if (str) {
96  FILE* f = fopen(logFilename.c_str(), "a");
97  if (f) {
98  fputs(str,f);
99  fclose(f);
100  }
101  }
102 }
103 
104 std::string GetDirectoryFromPath(std::string fullpath)
105 {
106  for (int i=fullpath.size()-1;i>=0;i--) {
107  if (fullpath[i] == '/' || fullpath[i] == '\\') {
108  return fullpath.substr(0, i);
109  }
110  }
111  return "";
112 }
113 
114 std::string GetLocalModulePath()
115 {
116  std::string dllpath = GetLocalModuleFilename();
117  return GetDirectoryFromPath(dllpath);
118 }
119 
120 
121 std::string file_ext(const char *f){
122  int l=strlen(f)-1;
123  while (l > 0) {
124  if (f[l] == '.')
125  return &f[l+1];
126  l--;
127  }
128  return "";
129 }
130 
131 
132 std::string SPrintf(const char *fmt, ...) {
133  va_list ap;
134  va_start(ap, fmt);
135 
136  char buf[512];
137  VSNPRINTF(buf, sizeof(buf), fmt, ap);
138 
139  va_end(ap);
140  return buf;
141 }
142 
143 void dbgout(const std::string& s) {
144  OutputDebugString(s.c_str());
145  printf(s.c_str());
146  WriteToLog(s.c_str());
147 }
148 
149 void dbgprintf(const char *fmt,...) {
150  va_list ap;
151  va_start(ap, fmt);
152 
153  char buf[512];
154  VSNPRINTF(buf, sizeof(buf), fmt, ap);
155  OutputDebugString(buf);
156  fputs(buf,stdout);
157  WriteToLog(buf);
158 
159  va_end(ap);
160 }
161 
162 void GenerateTestImage(ImageData& img, float xp, float yp, float size, float SNratio)
163 {
164  float S = 1.0f/sqrt(size);
165  for (int y=0;y<img.h;y++) {
166  for (int x=0;x<img.w;x++) {
167  float X = x - xp;// + 0.5;
168  float Y = y - yp;// + 0.5;
169  float r = sqrtf(X*X+Y*Y)+1;
170  float v = sinf(r/(5*S)) * expf(-r*r*S*0.001f);
171  img.at(x,y)=v;
172  }
173  }
174 
175  if (SNratio>0) {
176  ApplyGaussianNoise(img, 1.0f/SNratio);
177  }
178  img.normalize();
179 }
180 
181 void ComputeCRP(float* dst, int radialSteps, int angularSteps, float minradius, float maxradius,
182  vector2f center, ImageData* img, float paddingValue, float*crpmap)
183 {
184  vector2f* radialDirs = (vector2f*)ALLOCA(sizeof(vector2f)*angularSteps);
185  for (int j=0;j<angularSteps;j++) {
186  float ang = 2*3.141593f*j/(float)angularSteps;
187  radialDirs[j] = vector2f(cosf(ang), sinf(ang) );
188  }
189 
190  for (int i=0;i<radialSteps;i++)
191  dst[i]=0.0f;
192 
193  float* map = crpmap ? crpmap : (float*)ALLOCA(sizeof(float)*radialSteps*angularSteps);
194  float* com = (float*)ALLOCA(sizeof(float)*angularSteps);
195 
196  float rstep = (maxradius-minradius) / radialSteps;
197  float comsum = 0.0f;
198  for (int a=0;a<angularSteps;a++) {
199  float r = minradius;
200  float sum = 0.0f, moment=0.0f;
201  for (int i=0;i<radialSteps; i++) {
202  float x = center.x + radialDirs[a].x * r;
203  float y = center.y + radialDirs[a].y * r;
204  float v = img->interpolate(x,y);
205  r += rstep;
206  map[a*radialSteps+i] = v;
207  sum += v;
208  moment += i*v;
209  }
210  com[a] = moment/sum;
211  comsum += com[a];
212  }
213  float avgcom = comsum/angularSteps;
214  float totalrmssum2 = 0.0f;
215  for (int i=0;i<radialSteps; i++) {
216  double sum = 0.0f;
217  for (int a=0;a<angularSteps;a++) {
218  float shift = com[a]-avgcom;
219  sum += map[a*radialSteps+i];
220  }
221  dst[i] = sum/angularSteps-paddingValue;
222  totalrmssum2 += dst[i]*dst[i];
223  }
224  double invTotalrms = 1.0f/sqrt(totalrmssum2/radialSteps);
225  for (int i=0;i<radialSteps;i++) {
226  dst[i] *= invTotalrms;
227  }
228 }
229 
230 // One-dimensional background corrected center-of-mass
231 float ComputeBgCorrectedCOM1D(float *data, int len, float cf)
232 {
233  float sum=0, sum2=0;
234  float moment=0;
235 
236  for (int x=0;x<len;x++) {
237  float v = data[x];
238  sum += v;
239  sum2 += v*v;
240  }
241 
242  float invN = 1.0f/len;
243  float mean = sum * invN;
244  float stdev = sqrtf(sum2 * invN - mean * mean);
245  sum = 0.0f;
246 
247  for(int x=0;x<len;x++)
248  {
249  float v = data[x];
250  v = std::max(0.0f, fabs(v-mean)-cf*stdev);
251  sum += v;
252  moment += x*v;
253  }
254  return moment / (float)sum;
255 }
256 
257 void NormalizeRadialProfile(scalar_t * prof, int rsteps)
258 {
259  double sum=0.0f;
260  for (int i=0;i<rsteps;i++)
261  sum += prof[i];
262 
263  float mean =sum/rsteps;
264  double rmssum2 = 0.0;
265 
266  for (int i=0;i<rsteps;i++) {
267  prof[i] -= mean;
268  rmssum2 += prof[i]*prof[i];
269  }
270  double invTotalrms = 1.0f/sqrt(rmssum2/rsteps);
271  for (int i=0;i<rsteps;i++)
272  prof[i] *= invTotalrms;
273 
274 /*
275  scalar_t minVal = prof[0];
276  for (int i=0;i<rsteps;i++)
277  if(prof[i]<minVal) minVal=prof[i];
278 
279  float rms=0;
280  for (int i=0;i<rsteps;i++) {
281  prof[i]-=minVal;
282  rms += prof[i]*prof[i];
283  }
284  rms=1.0f/sqrt(rms);
285  for (int i=0;i<rsteps;i++) {
286  prof[i]*=rms;
287  }*/
288 }
289 
290 
291 void NormalizeZLUT(float* zlut ,int numBeads, int planes, int radialsteps)
292 {
293  for(int i=0;i<numBeads;i++)
294  for (int j=0;j<planes;j++)
295  NormalizeRadialProfile(&zlut[radialsteps*planes*i + radialsteps*j], radialsteps);
296 }
297 
298 void ComputeRadialProfile(float* dst, int radialSteps, int angularSteps, float minradius, float maxradius,
299  vector2f center, ImageData* img, float mean, bool normalize)
300 {
301  vector2f* radialDirs = (vector2f*)ALLOCA(sizeof(vector2f)*angularSteps);
302  for (int j=0;j<angularSteps;j++) {
303  float ang = 2*3.141593f*j/(float)angularSteps;
304  radialDirs[j] = vector2f(cosf(ang), sinf(ang));
305  }
306 
307  for (int i=0;i<radialSteps;i++)
308  dst[i]=0.0f;
309 
310 // center.x += 0.5f;
311 // center.y += 0.5f;
312 
313  bool trace=false;
314  float rstep = (maxradius-minradius) / radialSteps;
315  int totalsmp = 0;
316 
317  //FILE* f = fopen("D:\\TestImages\\test.csv","w");
318 
319  for (int i=0;i<radialSteps; i++) {
320  double sum = 0.0f;
321 
322  int nsamples = 0;
323  float r = minradius+rstep*i;
324  for (int a=0;a<angularSteps;a++) {
325  float x = center.x + radialDirs[a].x * r;
326  float y = center.y + radialDirs[a].y * r;
327  bool outside;
328  float v = img->interpolate(x,y, &outside);
329  if (!outside) {
330  sum += v;
331  nsamples++;
332  }
333 
334  //fprintf(f,"%d\t%d\t%f\n",i,a,v);
335  }
336 
337  if (trace) {
338  dbgprintf("%f,[%d]; ", sum, nsamples);
339  }
340 
341  dst[i] = nsamples > MIN_RADPROFILE_SMP_COUNT ? sum/nsamples : mean;
342  }
343  if(trace)
344  dbgprintf("\n");
345 
346  //fclose(f);
347 
348  if (normalize)
349  NormalizeRadialProfile(dst, radialSteps);
350 }
351 
352 inline float sq(float x) { return x*x; }
353 
354 void GenerateImageFromLUT(ImageData* image, ImageData* zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
355 {
356 // lut.w = radialcov * ( (image->w/2 * roicov ) - minradius );
357 // lut.w = radialcov * ( maxradius - minradius );
358 
359  float radialcov = zlut->w / (maxradius-minradius);
360  float* zinterp = (float*)ALLOCA(zlut->w * sizeof(float));
361 
362  if (splineInterp) {
363  int iz = std::max(1, std::min(zlut->h-3, (int)pos.z));
364  float weights[4];
365  float fz = pos.z-iz;
366  ComputeBSplineWeights(weights, fz);
367  // Interpolate ZLUT using B-spline weights
368  for (int r=0;r<zlut->w;r++) {
369  float zlutv = 0;
370  for (int i=0;i<4;i++)
371  zlutv += weights[i] * zlut->at(r, i-1+iz);
372  zinterp[r] = zlutv;
373  }
374  }
375  else {
376  // The two Z planes to interpolate between
377  int iz = (int)pos.z;
378  if (iz < 0)
379  zinterp = zlut->data;
380  else if (iz>=zlut->h-1)
381  zinterp = &zlut->data[ (zlut->h-1)*zlut->w ];
382  else {
383  float* zlut0 = &zlut->data [ (int)pos.z * zlut->w ];
384  float* zlut1 = &zlut->data [ ((int)pos.z + 1) * zlut->w ];
385  zinterp = (float*)ALLOCA(sizeof(float)*zlut->w);
386  for (int r=0;r<zlut->w;r++)
387  zinterp[r] = Lerp(zlut0[r], zlut1[r], pos.z-iz);
388  }
389  }
390 
391  int oversampleWidth=oversampleSubdiv,oversampleHeight=oversampleSubdiv;
392  float oxstep = 1.0f / oversampleWidth;
393  float oystep = 1.0f / oversampleHeight;
394 
395  for (int y=0;y<image->h;y++)
396  for (int x=0;x<image->w;x++)
397  {
398  float s = 0.0f;
399 
400  for (int ox=0;ox<oversampleWidth;ox++)
401  for (int oy=0;oy<oversampleHeight;oy++) {
402 
403  float X = x+(ox+0.5f)*oxstep - pos.x - 0.5f;
404  float Y = y+(oy+0.5f)*oystep - pos.y - 0.5f;
405 
406  float pixr = sqrtf(X*X+Y*Y);
407  float r = (pixr - minradius) * radialcov;
408 
409  if (r > zlut->w-2)
410  r = zlut->w-2;
411  if (r < 0) r = 0;
412 
413  int i=(int)r;
414  s += Lerp(zinterp[i], zinterp[i+1], r-i);
415  }
416 
417  image->at(x,y) = s/(oversampleWidth*oversampleHeight);
418  }
419 }
420 
421 void GenerateGaussianSpotImage(ImageData* img, vector2f pos, float sigma, float I0, float Ibg)
422 {
423  float edenom = 1/sqrt(2*sigma*sigma);
424  for (int y=0;y<img->h;y++)
425  for(int x=0;x<img->w;x++) {
426  float DeltaX = 0.5f * erf( (x-pos.x + .5f) * edenom ) - 0.5f * erf((x-pos.x - .5f) * edenom);
427  float DeltaY = 0.5f * erf( (y-pos.y + .5f) * edenom ) - 0.5f * erf((y-pos.y - .5f) * edenom);
428  img->at(x,y) = Ibg + I0 * DeltaX * DeltaY;
429  }
430 }
431 
432 void ApplyPoissonNoise(ImageData& img, float poissonMax, float maxval)
433 {
434  /*auto f = [&] (int y) {
435  for (int x=0;x<img.w;x++) {
436  img.at(x,y) = rand_poisson<float>(factor*img.at(x,y));
437  }
438  };
439 
440  ThreadPool<int, std::function<void (int index)> > pool(f);
441 
442  for (int y=0;y<img.h;y++) {
443  pool.AddWork(y);
444  }
445  pool.WaitUntilDone();*/
446 
447  float ratio = maxval / poissonMax;
448 
449  for (int x=0;x<img.numPixels();x++) {
450  img[x] = (int)(rand_poisson<float>(poissonMax*img[x]) * ratio );
451  }
452 }
453 
454 void ApplyGaussianNoise(ImageData& img, float sigma)
455 {
456  for (int k=0;k<img.numPixels();k++) {
457  float v = img.data[k] + sigma * rand_normal<float>();
458  if (v<0.0f) v= 0.0f;
459  img.data[k]=v;
460  }
461 }
462 
463 std::vector< std::vector<float> > ReadCSV(const char *filename, char sep)
464 {
465  std::list< std::vector <float> > data;
466 
467  FILE *f=fopen(filename,"r");
468  if (f) {
469  std::string buf;
470  std::vector<float> vals;
471  while (!feof(f)) {
472  char c=fgetc(f);
473  if (c == sep || c=='\n') {
474  vals.push_back( atof(buf.c_str()) );
475  buf.clear();
476  }
477  if (c == '\n') {
478  data.push_back( vals );
479  vals.clear();
480  }
481 
482  if (c != sep && c!= '\n')
483  buf+=c;
484  }
485  fclose(f);
486  }
487 
488  std::vector<std::vector<float> > r;
489  r.reserve(data.size());
490  r.insert(r.begin(), data.begin(), data.end());
491  return r;
492 }
493 
494 std::vector<vector3f> ReadVector3CSV( const char *file, char sep )
495 {
496  auto data=ReadCSV(file ,sep);
497 
498  std::vector<vector3f> r(data.size());
499 
500  for (uint i=0;i<data.size();i++){
501  r[i]=vector3f(data[i][0],data[i][1],data[i][2]);
502  }
503  return r;
504 }
505 
506 
507 void WriteTrace(std::string filename, vector3f* results, int nResults)
508 {
509  FILE *f = fopen(filename.c_str(), "w");
510 
511  if (!f) {
512  throw std::runtime_error(SPrintf("Can't open %s", filename.c_str()));
513  }
514 
515  for (int i=0;i<nResults;i++)
516  {
517  fprintf(f, "%.7f\t%.7f\t%.7f\n", results[i].x, results[i].y, results[i].z);
518  }
519 
520  fclose(f);
521 }
522 
523 void WriteVectorAsCSVRow(const char *file, std::vector<float> d, bool append)
524 {
525  FILE *f = fopen(file, append?"a":"w");
526  if(f) {
527  for (uint i=0;i<d.size();i++)
528  fprintf(f, "%1.7f\t", d[i]);
529 
530  fprintf(f, "\n");
531  fclose(f);
532  }
533  else
534  dbgprintf("WriteArrayAsCSVRow: Unable to open file %s\n", file);
535 }
536 
537 void WriteArrayAsCSVRow(const char *file, float* d, int len, bool append)
538 {
539  FILE *f = fopen(file, append?"a":"w");
540  if(f) {
541  for (int i=0;i<len;i++)
542  fprintf(f, "%.7f\t", d[i]);
543 
544  fprintf(f, "\n");
545  fclose(f);
546  }
547  else
548  dbgprintf("WriteArrayAsCSVRow: Unable to open file %s\n", file);
549 }
550 
551 void WriteImageAsCSV(const char* file, float* d, int w,int h, const char* labels[])
552 {
553  FILE* f = fopen(file, "w");
554 
555  if (f) {
556 
557  if (labels) {
558  for (int i=0;i<w;i++) {
559  fprintf(f, "%s;\t", labels[i]);
560  }
561  fputs("\n", f);
562  }
563 
564  for (int y=0;y<h;y++) {
565  for (int x=0;x<w;x++)
566  {
567  fprintf(f, "%.10f", d[y*w+x]);
568  if(x<w-1) fputs("\t", f);
569  }
570  fprintf(f, "\n");
571  }
572 
573  fclose(f);
574  }
575  else
576  dbgprintf("WriteImageAsCSV: Unable to open file %s\n", file);
577 }
578 
579 void WriteComplexImageAsCSV(const char* file, std::complex<float>* d, int w,int h, const char* labels[])
580 {
581  FILE* f = fopen(file, "w");
582 
583  if (!f) {
584  dbgprintf("WriteComplexImageAsCSV: Unable to open file %s\n", file);
585  return;
586  }
587 
588  if (labels) {
589  for (int i=0;i<w;i++) {
590  fprintf(f, "%s;\t", labels[i]);
591  }
592  fputs("\n", f);
593  }
594 
595  for (int y=0;y<h;y++) {
596  for (int x=0;x<w;x++)
597  {
598  float i=d[y*w+x].imag();
599  fprintf(f, "%f%+fi", d[y*w+x].real(), i);
600  if(x<w-1) fputs("\t", f);
601  }
602  fprintf(f, "\n");
603  }
604 
605  fclose(f);
606 }
607 
608 std::vector<uchar> ReadToByteBuffer(const char *filename)
609 {
610  FILE *f = fopen(filename, "rb");
611 
612  if (!f)
613  throw std::runtime_error(SPrintf("%s was not found", filename));
614 
615  fseek(f, 0, SEEK_END);
616  int len = ftell(f);
617  fseek(f, 0, SEEK_SET);
618 
619  std::vector<uchar> buf(len);
620  fread(&buf[0], 1,len, f);
621 
622  fclose(f);
623  return buf;
624 }
625 
626 ImageData ReadJPEGFile(const char*fn)
627 {
628  int w, h;
629  uchar* imgdata;
630  std::vector<uchar> jpgdata = ReadToByteBuffer(fn);
631  ReadJPEGFile(&jpgdata[0], jpgdata.size(), &imgdata, &w,&h);
632 
633  float* fbuf = new float[w*h];
634  for (int x=0;x<w*h;x++)
635  fbuf[x] = imgdata[x]/255.0f;
636  delete[] imgdata;
637 
638  return ImageData(fbuf,w,h);
639 }
640 
641 void CopyImageToFloat(uchar* data, int width, int height, int pitch, QTRK_PixelDataType pdt, float* dst)
642 {
643  if (pdt == QTrkU8) {
644  for (int y=0;y<height;y++) {
645  for (int x=0;x<width;x++)
646  dst[x] = data[x];
647  data += pitch;
648  dst += width;
649  }
650  } else if(pdt == QTrkU16) {
651  for (int y=0;y<height;y++) {
652  ushort* u = (ushort*)data;
653  for (int x=0;x<width;x++)
654  dst[x] = u[x];
655  data += pitch;
656  dst += width;
657  }
658  } else {
659  for (int y=0;y<height;y++) {
660  float* fsrc = (float*)data;
661  for( int x=0;x<width;x++)
662  dst[x] = fsrc[x];
663  data += pitch;
664  dst += width;
665  }
666  }
667 }
668 
670 {
671  uint64_t freq, time;
672 
673  QueryPerformanceCounter((LARGE_INTEGER*)&time);
674  QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
675 
676  return (double)time / (double)freq;
677 }
678 
679 int NearestPowerOf2(int v)
680 {
681  int r=1;
682  while (r < v)
683  r *= 2;
684  if ( fabsf(r-v) < fabsf(r/2-v) )
685  return r;
686  return r/2;
687 }
688 
689 int NearestPowerOf3(int v)
690 {
691  int r=1;
692  while (r < v)
693  r *= 3;
694  if ( fabsf(r-v) < fabsf(r/3-v) )
695  return r;
696  return r/3;
697 }
698 
706 std::vector<float> ComputeRadialBinWindow(int rsteps)
707 {
708  std::vector<float> wnd(rsteps);
709  for (int i=0;i<rsteps;i++) {
710  float x = i/(float)rsteps;
711  float t2 = 0.05f;
712  float t1 = 0.01f;
713  float fall = 1.0f-expf(-sq(1-x)/t2);
714  float rise = 1.0f-expf(-sq(x)/t1);
715  wnd[i] = sqrtf(fall*rise*x*2);
716  }
717  return wnd;
718 }
719 
720 ImageData ReadLUTFile(const char *lutfile)
721 {
722  PathSeperator sep(lutfile);
723  if(sep.extension == "jpg") {
724  return ReadJPEGFile(lutfile);
725  }
726  else {
727  std::string fn = lutfile;
728  fn = std::string(fn.begin(), fn.begin()+fn.find('#'));
729  std::string num( ++( sep.extension.begin() + sep.extension.find('#') ), sep.extension.end());
730  int lutIndex = atoi(num.c_str());
731 
732  int nbeads, nplanes, nsteps;
733  FILE *f = fopen(fn.c_str(), "rb");
734 
735  if (!f)
736  throw std::runtime_error("Can't open " + fn);
737 
738  fread(&nbeads, 4, 1, f);
739  fread(&nplanes, 4, 1, f);
740  fread(&nsteps, 4, 1, f);
741 
742 
743  fseek(f, 12 + 4* (nsteps*nplanes * lutIndex), SEEK_SET);
744  ImageData lut = ImageData::alloc(nsteps,nplanes);
745  fread(lut.data, 4, nsteps*nplanes,f);
746  fclose(f);
747  lut.normalize();
748  return lut;
749  }
750 }
void WriteArrayAsCSVRow(const char *file, float *d, int len, bool append)
Definition: utils.cpp:537
void GetFormattedTimeString(char *output)
Definition: utils.cpp:38
std::string filename
Definition: utils.h:180
float ComputeBgCorrectedCOM1D(float *data, int len, float cf)
Definition: utils.cpp:231
void GenerateTestImage(ImageData &img, float xp, float yp, float size, float SNratio)
Definition: utils.cpp:162
int NearestPowerOf2(int v)
Definition: utils.cpp:679
std::string GetDirectoryFromPath(std::string fullpath)
Definition: utils.cpp:104
std::string directory
Definition: utils.h:180
void ApplyGaussianNoise(ImageData &img, float sigma)
Definition: utils.cpp:454
TImageData< float > ImageData
Definition: QueuedTracker.h:69
void dbgout(const std::string &s)
Definition: utils.cpp:143
int NearestPowerOf3(int v)
Definition: utils.cpp:689
16 bit unsigned int
Definition: qtrk_c_api.h:36
void WriteVectorAsCSVRow(const char *file, std::vector< float > d, bool append)
Definition: utils.cpp:523
std::string file_ext(const char *f)
Definition: utils.cpp:121
ImageData ReadLUTFile(const char *lutfile)
Definition: utils.cpp:720
std::vector< std::vector< float > > ReadCSV(const char *filename, char sep)
Definition: utils.cpp:463
unsigned int uint
Definition: std_incl.h:127
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
Definition: utils.cpp:354
T erf(T x)
Definition: utils.h:373
void normalize(TPixel *d, uint w, uint h)
Definition: utils.h:27
void WriteTrace(std::string filename, vector3f *results, int nResults)
Definition: utils.cpp:507
PathSeperator(std::string fullpath)
Definition: utils.cpp:70
void NormalizeRadialProfile(scalar_t *prof, int rsteps)
Definition: utils.cpp:257
unsigned short ushort
Definition: std_incl.h:128
vector2< float > vector2f
Definition: std_incl.h:39
8 bit unsigned int
Definition: qtrk_c_api.h:35
vector3< T > sqrt(const vector3< T > &a)
Definition: std_incl.h:112
std::vector< vector3f > ReadVector3CSV(const char *file, char sep)
Definition: utils.cpp:494
int numPixels() const
Definition: utils.h:99
T interpolate(float x, float y, bool *outside=0)
Definition: utils.h:97
static TImageData alloc(int w, int h)
Definition: utils.h:110
double GetPreciseTime()
Definition: utils.cpp:669
void normalize()
Definition: utils.h:101
T Lerp(T a, T b, float x)
Definition: utils.h:40
#define VSNPRINTF
Definition: std_incl.h:150
std::vector< uchar > ReadToByteBuffer(const char *filename)
Definition: utils.cpp:608
std::vector< float > ComputeRadialBinWindow(int rsteps)
Calculate the radial weights for ZLUT profile comparisons.
Definition: utils.cpp:706
ImageData ReadJPEGFile(const char *fn)
Definition: utils.cpp:626
std::string GetLocalModulePath()
Definition: utils.cpp:114
float scalar_t
Definition: scalar_types.h:9
#define MIN_RADPROFILE_SMP_COUNT
Minimum number of samples for a profile radial bin. Below this the image mean will be used...
Definition: QueuedTracker.h:74
std::string extension
Definition: utils.h:180
void GenerateGaussianSpotImage(ImageData *img, vector2f pos, float sigma, float I0, float Ibg)
Definition: utils.cpp:421
std::string GetCurrentOutputPath(bool ext)
Definition: utils.cpp:19
void dbgsetlogfile(const char *path)
Definition: utils.cpp:49
QTRK_PixelDataType
Flags indicating the data type of image data.
Definition: qtrk_c_api.h:33
void WriteComplexImageAsCSV(const char *file, std::complex< float > *d, int w, int h, const char *labels[])
Definition: utils.cpp:579
float sq(float x)
Definition: utils.cpp:352
void CopyImageToFloat(uchar *data, int width, int height, int pitch, QTRK_PixelDataType pdt, float *dst)
Copies image data from a generic QTRK_PixelDataType array to a float array.
Definition: utils.cpp:641
int h
Definition: utils.h:81
static std::string logFilename
Definition: utils.cpp:47
void WriteToLog(const char *str)
Definition: utils.cpp:88
vector3< float > vector3f
Definition: std_incl.h:114
void dbgprintf(const char *fmt,...)
Definition: utils.cpp:149
T & at(int x, int y)
Definition: utils.h:96
void ComputeCRP(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float paddingValue, float *crpmap)
Definition: utils.cpp:181
void ComputeRadialProfile(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float mean, bool normalize)
Definition: utils.cpp:298
void CUDA_SUPPORTED_FUNC ComputeBSplineWeights(float w[], float t)
Definition: CubicBSpline.h:15
#define ALLOCA(size)
Definition: std_incl.h:151
std::string GetLocalModuleFilename()
Definition: utils.cpp:54
void WriteImageAsCSV(const char *file, float *d, int w, int h, const char *labels[])
Definition: utils.cpp:551
unsigned char uchar
Definition: std_incl.h:130
std::string SPrintf(const char *fmt,...)
Definition: utils.cpp:132
T * data
Definition: utils.h:80
int w
Definition: utils.h:81
void NormalizeZLUT(float *zlut, int numBeads, int planes, int radialsteps)
Definition: utils.cpp:291
void ApplyPoissonNoise(ImageData &img, float poissonMax, float maxval)
Definition: utils.cpp:432