21 std::string base =
"D:\\TestImages\\TestOutput\\";
22 std::string search = base +
"*";
23 LPCSTR w_folder = _T(search.c_str());
25 WIN32_FIND_DATA FindFileData;
28 hFind = FindFirstFile(w_folder,&FindFileData);
30 while(FindNextFile(hFind,&FindFileData))
31 dirName = FindFileData.cFileName;
33 return SPrintf(
"%s%s\\%s",base.c_str(),dirName.c_str(),
"ZLUTDiag\\");
35 return SPrintf(
"%s%s",base.c_str(),dirName.c_str());
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);
60 GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
63 GetModuleFileNameA(hm, path,
sizeof(path));
66 #error GetLocalModuleName() not implemented for this platform 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()) {
79 if (fullpath[i] ==
'/' || fullpath[i] ==
'\\') {
85 filename = fullpath.substr(filenameStart, filenameEnd - filenameStart);
92 logFilename = ps.directory + ps.filename +
"-log.txt";
106 for (
int i=fullpath.size()-1;i>=0;i--) {
107 if (fullpath[i] ==
'/' || fullpath[i] ==
'\\') {
108 return fullpath.substr(0, i);
144 OutputDebugString(s.c_str());
155 OutputDebugString(buf);
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++) {
169 float r = sqrtf(X*X+Y*Y)+1;
170 float v = sinf(r/(5*S)) * expf(-r*r*S*0.001f);
181 void ComputeCRP(
float* dst,
int radialSteps,
int angularSteps,
float minradius,
float maxradius,
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) );
190 for (
int i=0;i<radialSteps;i++)
193 float* map = crpmap ? crpmap : (
float*)
ALLOCA(
sizeof(
float)*radialSteps*angularSteps);
194 float* com = (
float*)
ALLOCA(
sizeof(
float)*angularSteps);
196 float rstep = (maxradius-minradius) / radialSteps;
198 for (
int a=0;a<angularSteps;a++) {
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;
206 map[a*radialSteps+i] = v;
213 float avgcom = comsum/angularSteps;
214 float totalrmssum2 = 0.0f;
215 for (
int i=0;i<radialSteps; i++) {
217 for (
int a=0;a<angularSteps;a++) {
218 float shift = com[a]-avgcom;
219 sum += map[a*radialSteps+i];
221 dst[i] = sum/angularSteps-paddingValue;
222 totalrmssum2 += dst[i]*dst[i];
224 double invTotalrms = 1.0f/
sqrt(totalrmssum2/radialSteps);
225 for (
int i=0;i<radialSteps;i++) {
226 dst[i] *= invTotalrms;
236 for (
int x=0;x<len;x++) {
242 float invN = 1.0f/len;
243 float mean = sum * invN;
244 float stdev = sqrtf(sum2 * invN - mean * mean);
247 for(
int x=0;x<len;x++)
250 v = std::max(0.0f, fabs(v-mean)-cf*stdev);
254 return moment / (float)sum;
260 for (
int i=0;i<rsteps;i++)
263 float mean =sum/rsteps;
264 double rmssum2 = 0.0;
266 for (
int i=0;i<rsteps;i++) {
268 rmssum2 += prof[i]*prof[i];
270 double invTotalrms = 1.0f/
sqrt(rmssum2/rsteps);
271 for (
int i=0;i<rsteps;i++)
272 prof[i] *= invTotalrms;
293 for(
int i=0;i<numBeads;i++)
294 for (
int j=0;j<planes;j++)
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));
307 for (
int i=0;i<radialSteps;i++)
314 float rstep = (maxradius-minradius) / radialSteps;
319 for (
int i=0;i<radialSteps; i++) {
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;
352 inline float sq(
float x) {
return x*x; }
359 float radialcov = zlut->
w / (maxradius-minradius);
360 float* zinterp = (
float*)
ALLOCA(zlut->
w *
sizeof(
float));
363 int iz = std::max(1, std::min(zlut->
h-3, (
int)pos.
z));
368 for (
int r=0;r<zlut->
w;r++) {
370 for (
int i=0;i<4;i++)
371 zlutv += weights[i] * zlut->
at(r, i-1+iz);
379 zinterp = zlut->
data;
380 else if (iz>=zlut->
h-1)
381 zinterp = &zlut->
data[ (zlut->
h-1)*zlut->
w ];
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);
391 int oversampleWidth=oversampleSubdiv,oversampleHeight=oversampleSubdiv;
392 float oxstep = 1.0f / oversampleWidth;
393 float oystep = 1.0f / oversampleHeight;
395 for (
int y=0;y<image->h;y++)
396 for (
int x=0;x<image->w;x++)
400 for (
int ox=0;ox<oversampleWidth;ox++)
401 for (
int oy=0;oy<oversampleHeight;oy++) {
403 float X = x+(ox+0.5f)*oxstep - pos.x - 0.5f;
404 float Y = y+(oy+0.5f)*oystep - pos.y - 0.5f;
406 float pixr = sqrtf(X*X+Y*Y);
407 float r = (pixr - minradius) * radialcov;
414 s +=
Lerp(zinterp[i], zinterp[i+1], r-i);
417 image->at(x,y) = s/(oversampleWidth*oversampleHeight);
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;
447 float ratio = maxval / poissonMax;
450 img[x] = (int)(rand_poisson<float>(poissonMax*img[x]) * ratio );
457 float v = img.
data[k] + sigma * rand_normal<float>();
465 std::list< std::vector <float> > data;
467 FILE *f=fopen(filename,
"r");
470 std::vector<float> vals;
473 if (c == sep || c==
'\n') {
474 vals.push_back( atof(buf.c_str()) );
478 data.push_back( vals );
482 if (c != sep && c!=
'\n')
488 std::vector<std::vector<float> > r;
489 r.reserve(data.size());
490 r.insert(r.begin(), data.begin(), data.end());
498 std::vector<vector3f> r(data.size());
500 for (
uint i=0;i<data.size();i++){
501 r[i]=
vector3f(data[i][0],data[i][1],data[i][2]);
509 FILE *f = fopen(filename.c_str(),
"w");
512 throw std::runtime_error(
SPrintf(
"Can't open %s", filename.c_str()));
515 for (
int i=0;i<nResults;i++)
517 fprintf(f,
"%.7f\t%.7f\t%.7f\n", results[i].x, results[i].y, results[i].z);
525 FILE *f = fopen(file, append?
"a":
"w");
527 for (
uint i=0;i<d.size();i++)
528 fprintf(f,
"%1.7f\t", d[i]);
534 dbgprintf(
"WriteArrayAsCSVRow: Unable to open file %s\n", file);
539 FILE *f = fopen(file, append?
"a":
"w");
541 for (
int i=0;i<len;i++)
542 fprintf(f,
"%.7f\t", d[i]);
548 dbgprintf(
"WriteArrayAsCSVRow: Unable to open file %s\n", file);
553 FILE* f = fopen(file,
"w");
558 for (
int i=0;i<w;i++) {
559 fprintf(f,
"%s;\t", labels[i]);
564 for (
int y=0;y<h;y++) {
565 for (
int x=0;x<w;x++)
567 fprintf(f,
"%.10f", d[y*w+x]);
568 if(x<w-1) fputs(
"\t", f);
576 dbgprintf(
"WriteImageAsCSV: Unable to open file %s\n", file);
581 FILE* f = fopen(file,
"w");
584 dbgprintf(
"WriteComplexImageAsCSV: Unable to open file %s\n", file);
589 for (
int i=0;i<w;i++) {
590 fprintf(f,
"%s;\t", labels[i]);
595 for (
int y=0;y<h;y++) {
596 for (
int x=0;x<w;x++)
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);
610 FILE *f = fopen(filename,
"rb");
613 throw std::runtime_error(
SPrintf(
"%s was not found", filename));
615 fseek(f, 0, SEEK_END);
617 fseek(f, 0, SEEK_SET);
619 std::vector<uchar> buf(len);
620 fread(&buf[0], 1,len, f);
631 ReadJPEGFile(&jpgdata[0], jpgdata.size(), &imgdata, &w,&h);
633 float* fbuf =
new float[w*h];
634 for (
int x=0;x<w*h;x++)
635 fbuf[x] = imgdata[x]/255.0f;
644 for (
int y=0;y<height;y++) {
645 for (
int x=0;x<width;x++)
651 for (
int y=0;y<height;y++) {
653 for (
int x=0;x<width;x++)
659 for (
int y=0;y<height;y++) {
660 float* fsrc = (
float*)data;
661 for(
int x=0;x<width;x++)
673 QueryPerformanceCounter((LARGE_INTEGER*)&time);
674 QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
676 return (
double)time / (double)freq;
684 if ( fabsf(r-v) < fabsf(r/2-v) )
694 if ( fabsf(r-v) < fabsf(r/3-v) )
708 std::vector<float> wnd(rsteps);
709 for (
int i=0;i<rsteps;i++) {
710 float x = i/(float)rsteps;
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);
727 std::string fn = lutfile;
728 fn = std::string(fn.begin(), fn.begin()+fn.find(
'#'));
730 int lutIndex = atoi(num.c_str());
732 int nbeads, nplanes, nsteps;
733 FILE *f = fopen(fn.c_str(),
"rb");
736 throw std::runtime_error(
"Can't open " + fn);
738 fread(&nbeads, 4, 1, f);
739 fread(&nplanes, 4, 1, f);
740 fread(&nsteps, 4, 1, f);
743 fseek(f, 12 + 4* (nsteps*nplanes * lutIndex), SEEK_SET);
745 fread(lut.
data, 4, nsteps*nplanes,f);
void WriteArrayAsCSVRow(const char *file, float *d, int len, bool append)
void GetFormattedTimeString(char *output)
float ComputeBgCorrectedCOM1D(float *data, int len, float cf)
void GenerateTestImage(ImageData &img, float xp, float yp, float size, float SNratio)
int NearestPowerOf2(int v)
std::string GetDirectoryFromPath(std::string fullpath)
void ApplyGaussianNoise(ImageData &img, float sigma)
TImageData< float > ImageData
void dbgout(const std::string &s)
int NearestPowerOf3(int v)
void WriteVectorAsCSVRow(const char *file, std::vector< float > d, bool append)
std::string file_ext(const char *f)
ImageData ReadLUTFile(const char *lutfile)
std::vector< std::vector< float > > ReadCSV(const char *filename, char sep)
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
void normalize(TPixel *d, uint w, uint h)
void WriteTrace(std::string filename, vector3f *results, int nResults)
PathSeperator(std::string fullpath)
void NormalizeRadialProfile(scalar_t *prof, int rsteps)
vector2< float > vector2f
vector3< T > sqrt(const vector3< T > &a)
std::vector< vector3f > ReadVector3CSV(const char *file, char sep)
T interpolate(float x, float y, bool *outside=0)
static TImageData alloc(int w, int h)
T Lerp(T a, T b, float x)
std::vector< uchar > ReadToByteBuffer(const char *filename)
std::vector< float > ComputeRadialBinWindow(int rsteps)
Calculate the radial weights for ZLUT profile comparisons.
ImageData ReadJPEGFile(const char *fn)
std::string GetLocalModulePath()
#define MIN_RADPROFILE_SMP_COUNT
Minimum number of samples for a profile radial bin. Below this the image mean will be used...
void GenerateGaussianSpotImage(ImageData *img, vector2f pos, float sigma, float I0, float Ibg)
std::string GetCurrentOutputPath(bool ext)
void dbgsetlogfile(const char *path)
QTRK_PixelDataType
Flags indicating the data type of image data.
void WriteComplexImageAsCSV(const char *file, std::complex< float > *d, int w, int h, const char *labels[])
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.
static std::string logFilename
void WriteToLog(const char *str)
vector3< float > vector3f
void dbgprintf(const char *fmt,...)
void ComputeCRP(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float paddingValue, float *crpmap)
void ComputeRadialProfile(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *img, float mean, bool normalize)
void CUDA_SUPPORTED_FUNC ComputeBSplineWeights(float w[], float t)
std::string GetLocalModuleFilename()
void WriteImageAsCSV(const char *file, float *d, int w, int h, const char *labels[])
std::string SPrintf(const char *fmt,...)
void NormalizeZLUT(float *zlut, int numBeads, int planes, int radialsteps)
void ApplyPoissonNoise(ImageData &img, float poissonMax, float maxval)