6 template<
typename T>
bool isNAN(
const T& v) {
13 void dbgout(
const std::string& s);
14 std::string
SPrintf(
const char *fmt, ...);
20 for(
typename T::iterator i=c.begin();i!=c.end();++i)
26 template<
typename TPixel>
31 for (
uint k=0;k<w*h;k++) {
32 maxv = std::max(maxv, d[k]);
33 minv = std::min(minv, d[k]);
35 for (
uint k=0;k<w*h;k++)
36 d[k]=(d[k]-minv)/(maxv-minv);
40 inline T
Lerp(T a, T b,
float x) {
return a + (b-a)*x; }
43 inline T
Interpolate(T* image,
int width,
int height,
float x,
float y,
bool* outside=0)
46 if (rx<0 || ry <0 || rx+1 >= width || ry+1>=height) {
47 if (outside) *outside=
true;
50 if (outside) *outside=
false;
52 T v00 = image[width*ry+rx];
53 T v10 = image[width*ry+rx+1];
54 T v01 = image[width*(ry+1)+rx];
55 T v11 = image[width*(ry+1)+rx+1];
57 T v0 =
Lerp(v00, v10, x-rx);
58 T v1 =
Lerp(v01, v11, x-rx);
60 return Lerp(v0, v1, y-ry);
67 if (fx < 0)
return d[0];
68 if (fx >= len-1)
return d[len-1];
69 return (d[fx+1]-d[fx]) * (x-fx) + d[fx];
84 template<
typename Ta>
void set(Ta *src) {
for (
int i=0;i<w*
h;i++) data[i] = src[i]; }
86 if (!data ||
numPixels()!=src.numPixels()) {
89 if(src.data) { data=
new T[src.w*src.h]; }
94 for (
int i=0;i<w*
h;i++) dst[i]=data[i];
96 T&
at(
int x,
int y) {
return data[w*y+x]; }
100 int pitch()
const {
return sizeof(T)*w; }
104 for(
int x=0;x<w*
h;x++)
141 for (T* s = start; s!=end; ++s) {
142 sum+=*s; sum2+=(*s)*(*s);
145 T invN = 1.0f/(end-start);
147 return sqrt(sum2 * invN - mean * mean);
156 void ComputeCRP(
float* dst,
int radialSteps,
int angularSteps,
float minradius,
float maxradius,
vector2f center,
ImageData* src,
float mean,
float*crpmap=0);
159 void NormalizeZLUT(
float *zlut,
int numLUTs,
int planes,
int radialsteps);
167 void WriteImageAsCSV(
const char* file,
float* d,
int w,
int h,
const char *labels[]=0);
168 std::vector< std::vector<float> >
ReadCSV(
const char *filename,
char sep=
'\t');
169 std::vector<vector3f>
ReadVector3CSV(
const char *file,
char sep=
'\t');
183 std::string
file_ext(
const char *f);
203 for (
uint k=0;k<w*
h;k++) {
204 maxv = std::max(maxv, src[k]);
205 minv = std::min(minv, src[k]);
207 for (
uint k=0;k<w*
h;k++)
208 dst[k] = maxValue * (src[k]-minv) / (maxv-minv);
223 T sum = 0.0, sum2=0.0;
224 for (
int a=0;a<len;a++) {
226 sum2+=data[a]*data[a];
229 return sqrt(sum2 / len- mean * mean);
240 T value = data[p+start];
242 std::swap(data[p+start], data[end-1]);
246 for(
int i=start;i<end-1;i++)
248 std::swap(data[i], data[start+nSmallerItems]);
252 std::swap(data[start+nSmallerItems], data[end-1]);
258 int pivotpos = start+nSmallerItems;
261 else if (k < pivotpos)
262 return qselect(data, start, pivotpos, k);
264 return qselect(data, pivotpos+1, end, k);
286 const float&
operator()(
int i,
int j)
const {
return m[3*i+j]; }
288 float&
at(
int i,
int j) {
return m[3*i+j]; }
289 const float&
at(
int i,
int j)
const {
return m[3*i+j]; }
293 return at(0,0)*(
at(1,1)*
at(2,2)-
at(2,1)*
at(1,2))
300 float det = Determinant();
302 float invdet = 1/det;
304 result(0,0) = (
at(1,1)*
at(2,2)-
at(2,1)*
at(1,2))*invdet;
305 result(1,0) = -(
at(0,1)*
at(2,2)-
at(0,2)*
at(2,1))*invdet;
306 result(2,0) = (
at(0,1)*
at(1,2)-
at(0,2)*
at(1,1))*invdet;
307 result(0,1) = -(
at(1,0)*
at(2,2)-
at(1,2)*
at(2,0))*invdet;
308 result(1,1) = (
at(0,0)*
at(2,2)-
at(0,2)*
at(2,0))*invdet;
309 result(2,1) = -(
at(0,0)*
at(1,2)-
at(1,0)*
at(0,2))*invdet;
310 result(0,2) = (
at(1,0)*
at(2,1)-
at(2,0)*
at(1,1))*invdet;
311 result(1,2) = -(
at(0,0)*
at(2,1)-
at(2,0)*
at(0,1))*invdet;
312 result(2,2) = (
at(0,0)*
at(1,1)-
at(1,0)*
at(0,1))*invdet;
319 float det = Determinant();
321 float invdet = 1/det;
323 result(0,0) = (
at(1,1)*
at(2,2)-
at(2,1)*
at(1,2))*invdet;
324 result(0,1) = -(
at(0,1)*
at(2,2)-
at(0,2)*
at(2,1))*invdet;
325 result(0,2) = (
at(0,1)*
at(1,2)-
at(0,2)*
at(1,1))*invdet;
326 result(1,0) = -(
at(1,0)*
at(2,2)-
at(1,2)*
at(2,0))*invdet;
327 result(1,1) = (
at(0,0)*
at(2,2)-
at(0,2)*
at(2,0))*invdet;
328 result(1,2) = -(
at(0,0)*
at(1,2)-
at(1,0)*
at(0,2))*invdet;
329 result(2,0) = (
at(1,0)*
at(2,1)-
at(2,0)*
at(1,1))*invdet;
330 result(2,1) = -(
at(0,0)*
at(2,1)-
at(2,0)*
at(0,1))*invdet;
331 result(2,2) = (
at(0,0)*
at(1,1)-
at(1,0)*
at(0,1))*invdet;
355 for (
int i=0;i<9;i++)
362 dbgprintf(
"%f\t%f\t%f\n", m[0],m[1],m[2]);
363 dbgprintf(
"%f\t%f\t%f\n", m[3],m[4],m[5]);
364 dbgprintf(
"%f\t%f\t%f\n", m[6],m[7],m[8]);
377 T a2 = -0.284496736f;
379 T a4 = -1.453152027f;
390 T t = 1.0f/(1.0f + p*x);
391 T y = 1.0f - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);
void NormalizeZLUT(float *zlut, int numLUTs, int planes, int radialsteps)
int NearestPowerOf2(int v)
void WriteComplexImageAsCSV(const char *file, std::complex< float > *d, int w, int h, const char *labels[]=0)
std::string GetLocalModuleFilename()
std::string SPrintf(const char *fmt,...)
void FloatToJPEGFile(const char *name, const float *d, int w, int h)
const vector3f & row(int i) const
float ComputeBgCorrectedCOM1D(float *data, int len, float cf=2.0f)
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool useSplineInterp=true, int ovs=4)
T interpolate1D(int y, float x)
void floatToNormalizedInt(T *dst, const float *src, uint w, uint h, T maxValue)
Matrix3X3 & operator*=(float a)
const float & operator()(int i, int j) const
T qselect(T *data, int start, int end, int k)
float Determinant() const
void ApplyGaussianNoise(ImageData &img, float sigma)
void GenerateTestImage(ImageData &img, float xp, float yp, float size, float MaxPhotons)
CImageData(const TImageData< float > &src)
Matrix3X3(vector3f x, vector3f y, vector3f z)
void normalize(TPixel *d, uint w, uint h)
void dbgsetlogfile(const char *path)
void ApplyPoissonNoise(ImageData &img, float poissonMax, float maxValue=255)
std::string GetCurrentOutputPath(bool ext=true)
std::string file_ext(const char *f)
vector3< T > sqrt(const vector3< T > &a)
CImageData(const CImageData &other)
ImageData ReadLUTFile(const char *lutfile)
void WriteVectorAsCSVRow(const char *file, std::vector< float > d, bool append)
void WriteJPEGFile(uchar *data, int w, int h, const char *filename, int quality)
std::string GetDirectoryFromPath(std::string fullpath)
TImageData< float > ImageData
T interpolate(float x, float y, bool *outside=0)
static TImageData alloc(int w, int h)
T ComputeStdDev(T *data, int len)
T Lerp(T a, T b, float x)
void NormalizeRadialProfile(float *prof, int rsteps)
Matrix3X3 & operator+=(const Matrix3X3 &b)
void writeAsCSV(const char *filename, const char *labels[]=0)
Matrix3X3 Inverse() const
std::vector< vector3f > ReadVector3CSV(const char *file, char sep='\t')
Matrix3X3 InverseTranspose() const
std::vector< uchar > ReadToByteBuffer(const char *filename)
float & operator[](int i)
int NearestPowerOf3(int v)
TImageData(T *d, int w, int h)
void ComputeCRP(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *src, float mean, float *crpmap=0)
const float & at(int i, int j) const
void DeleteAllElems(T &c)
const float & operator[](int i) const
void dbgprintf(const char *fmt,...)
void GenerateGaussianSpotImage(ImageData *img, vector2f pos, float sigma, float I0, float Ibg)
void dbgout(const std::string &s)
void WriteImageAsCSV(const char *file, float *d, int w, int h, const char *labels[]=0)
CImageData & operator=(const CImageData &src)
vector3< float > vector3f
T Interpolate(T *image, int width, int height, float x, float y, bool *outside=0)
std::vector< std::vector< float > > ReadCSV(const char *filename, char sep='\t')
TImageData< double > ImageDatad
CImageData & operator=(const TImageData< float > &src)
std::vector< float > ComputeRadialBinWindow(int rsteps)
Calculate the radial weights for ZLUT profile comparisons.
T StdDeviation(T *start, T *end)
float & operator()(int i, int j)
void ComputeRadialProfile(float *dst, int radialSteps, int angularSteps, float minradius, float maxradius, vector2f center, ImageData *src, float mean, bool normalize)
T Interpolate1D(T *d, int len, float x)
ImageData ReadJPEGFile(const char *fn)
std::string GetLocalModulePath()
void WriteArrayAsCSVRow(const char *file, float *d, int len, bool append)
void GetFormattedTimeString(char *output)
void WriteTrace(std::string file, vector3f *results, int nResults)