QTrk
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SampleFisherMatrix Class Reference

#include <FisherMatrix.h>

Public Member Functions

 SampleFisherMatrix (float maxValue)
 
Matrix3X3 Compute (vector3f pos, vector3f delta, ImageData &lut, int w, int h, float zlutMinRadius, float zlutMaxRadius)
 
Matrix3X3 Compute (vector3f pos, vector3f delta, int w, int h, std::function< void(ImageData &out, vector3f pos)> imageGenerator)
 
Matrix3X3 ComputeAverageFisher (vector3f pos, int Nsamples, vector3f sampleRange, vector3f delta, int w, int h, std::function< void(ImageData &out, vector3f pos)> imggen)
 

Private Member Functions

template<typename T >
void ImgDeriv (TImageData< T > &imgpx, TImageData< T > &imgmx, T delta)
 
template<typename T >
double FisherElem (TImageData< T > &mu, TImageData< T > &muderiv1, TImageData< T > &muderiv2)
 

Private Attributes

float maxValue
 

Detailed Description

Definition at line 8 of file FisherMatrix.h.

Constructor & Destructor Documentation

§ SampleFisherMatrix()

SampleFisherMatrix::SampleFisherMatrix ( float  maxValue)
inline

Definition at line 33 of file FisherMatrix.h.

34  {
35  this->maxValue = maxValue;
36  }

Member Function Documentation

§ Compute() [1/2]

Matrix3X3 SampleFisherMatrix::Compute ( vector3f  pos,
vector3f  delta,
ImageData lut,
int  w,
int  h,
float  zlutMinRadius,
float  zlutMaxRadius 
)
inline

Definition at line 38 of file FisherMatrix.h.

39  {
40  return Compute(pos, delta, w,h,[&](ImageData& out, vector3f pos) {
41  ImageData tmp = ImageData::alloc(w,h);
42  GenerateImageFromLUT(&tmp, &lut, zlutMinRadius, zlutMaxRadius, pos);
43  out.set(tmp);
44  tmp.free();
45  });
46  }
void GenerateImageFromLUT(ImageData *image, ImageData *zlut, float minradius, float maxradius, vector3f pos, bool splineInterp, int oversampleSubdiv)
Definition: utils.cpp:354
void set(Ta *src)
Definition: utils.h:84
static TImageData alloc(int w, int h)
Definition: utils.h:110
void free()
Definition: utils.h:111
Matrix3X3 Compute(vector3f pos, vector3f delta, ImageData &lut, int w, int h, float zlutMinRadius, float zlutMaxRadius)
Definition: FisherMatrix.h:38

§ Compute() [2/2]

Matrix3X3 SampleFisherMatrix::Compute ( vector3f  pos,
vector3f  delta,
int  w,
int  h,
std::function< void(ImageData &out, vector3f pos)>  imageGenerator 
)
inline

Definition at line 48 of file FisherMatrix.h.

49  {
50  static int t=0;
51 
52  // compute derivatives
53  auto mu = ImageData::alloc(w,h);
54  imageGenerator(mu, pos);
55 
56  float maxImg = mu.mean();
57 
58  auto imgpx = ImageData::alloc(w,h);
59  auto imgpy = ImageData::alloc(w,h);
60  auto imgpz = ImageData::alloc(w,h);
61  imageGenerator(imgpx, vector3f(pos.x+delta.x, pos.y,pos.z));
62  imageGenerator(imgpy, vector3f(pos.x, pos.y+delta.y,pos.z));
63  imageGenerator(imgpz, vector3f(pos.x, pos.y,pos.z+delta.z));
64 
65 // WriteImageAsCSV("imgpx.csv", imgpx.data, imgpx.w, imgpx.h);
66 // WriteImageAsCSV("imgpy.csv", imgpy.data, imgpx.w, imgpx.h);
67 // WriteImageAsCSV("imgpz.csv", imgpz.data, imgpx.w, imgpx.h);
68 
69  auto imgmx = ImageData::alloc(w,h);
70  auto imgmy = ImageData::alloc(w,h);
71  auto imgmz = ImageData::alloc(w,h);
72  imageGenerator(imgmx, vector3f(pos.x-delta.x, pos.y,pos.z));
73  imageGenerator(imgmy, vector3f(pos.x, pos.y-delta.y,pos.z));
74  imageGenerator(imgmz, vector3f(pos.x, pos.y,pos.z-delta.z));
75  //WriteImageAsCSV("imgmx.csv", imgmx.data, imgpx.w, imgpx.h);
76  //WriteImageAsCSV("imgmy.csv", imgmy.data, imgpx.w, imgpx.h);
77  //WriteImageAsCSV("imgmz.csv", imgmz.data, imgpx.w, imgpx.h);
78 
79  ImgDeriv(imgpx, imgmx, delta.x);
80  ImgDeriv(imgpy, imgmy, delta.y);
81  ImgDeriv(imgpz, imgmz, delta.z);
82 
83 // WriteJPEGFile("mu_dx.jpg", imgpx);
84 // WriteJPEGFile("mu_dy.jpg", imgpy);
85 // WriteJPEGFile("mu_dz.jpg", imgpz);
86  t++;
87 
88  double Ixx = FisherElem(mu, imgpx, imgpx);
89  double Iyy = FisherElem(mu, imgpy, imgpy);
90  double Izz = FisherElem(mu, imgpz, imgpz);
91  double Ixy = FisherElem(mu, imgpx, imgpy);
92  double Ixz = FisherElem(mu, imgpx, imgpz);
93  double Iyz = FisherElem(mu, imgpy, imgpz);
94 
95  Matrix3X3 fisher;
96  fisher(0,0) = Ixx; fisher(0,1) = Ixy; fisher(0,2) = Ixz;
97  fisher(1,0) = Ixy; fisher(1,1) = Iyy; fisher(1,2) = Iyz;
98  fisher(2,0) = Ixz; fisher(2,1) = Iyz; fisher(2,2) = Izz;
99  fisher *= maxValue / maxImg;
100 
101  imgpx.free(); imgpy.free(); imgpz.free();
102  imgmx.free(); imgmy.free(); imgmz.free();
103  mu.free();
104  return fisher;
105  }
void ImgDeriv(TImageData< T > &imgpx, TImageData< T > &imgmx, T delta)
Definition: FisherMatrix.h:14
static TImageData alloc(int w, int h)
Definition: utils.h:110
double FisherElem(TImageData< T > &mu, TImageData< T > &muderiv1, TImageData< T > &muderiv2)
Definition: FisherMatrix.h:22
vector3< float > vector3f
Definition: std_incl.h:114

§ ComputeAverageFisher()

Matrix3X3 SampleFisherMatrix::ComputeAverageFisher ( vector3f  pos,
int  Nsamples,
vector3f  sampleRange,
vector3f  delta,
int  w,
int  h,
std::function< void(ImageData &out, vector3f pos)>  imggen 
)
inline

Definition at line 107 of file FisherMatrix.h.

108  {
109  Matrix3X3* results = new Matrix3X3[Nsamples];
110 
111  auto f = [&] (int index) {
112  vector3f smpPos = pos + sampleRange*vector3f(rand_uniform<float>()-0.5f,rand_uniform<float>()-0.5f, rand_uniform<float>());
113  //vector3f smpPos = pos + ( vector3f(rand_normal<float>(), rand_normal<float>(), rand_normal<float>()) * initialStDev);
114  results[index] = Compute(smpPos, delta, w,h, imggen);
115  // dbgprintf("%d done.\n", index);
116  };
117 
118  if (0) {
120 
121  for (int i=0;i<Nsamples;i++)
122  pool.AddWork(i);
123  pool.WaitUntilDone();
124  } else {
125  for (int i=0;i<Nsamples;i++)
126  f(i);
127  }
128  Matrix3X3 accum;
129  for (int i=0;i<Nsamples;i++)
130  accum += results[i];
131  delete[] results;
132 
133  Matrix3X3 matrix = accum;
134  matrix *= 1.0f/Nsamples;
135  return matrix;
136  }
vector3< float > vector3f
Definition: std_incl.h:114
Matrix3X3 Compute(vector3f pos, vector3f delta, ImageData &lut, int w, int h, float zlutMinRadius, float zlutMaxRadius)
Definition: FisherMatrix.h:38

§ FisherElem()

template<typename T >
double SampleFisherMatrix::FisherElem ( TImageData< T > &  mu,
TImageData< T > &  muderiv1,
TImageData< T > &  muderiv2 
)
inlineprivate

Definition at line 22 of file FisherMatrix.h.

23  {
24  double sum = 0;
25  for (int y=0;y<mu.h;y++) {
26  for (int x=0;x<mu.w;x++)
27  sum += (double)muderiv1.at(x,y) * (double) muderiv2.at(x,y) / (1e-5f + (double)mu.at(x,y));
28  }
29  return sum;
30  }
int h
Definition: utils.h:81
T & at(int x, int y)
Definition: utils.h:96
int w
Definition: utils.h:81

§ ImgDeriv()

template<typename T >
void SampleFisherMatrix::ImgDeriv ( TImageData< T > &  imgpx,
TImageData< T > &  imgmx,
delta 
)
inlineprivate

Definition at line 14 of file FisherMatrix.h.

15  {
16  T inv2d = 1.0f/(2*delta);
17  for (int y=0;y<imgpx.w*imgpx.h;y++)
18  imgpx[y] = (imgpx[y] - imgmx[y]) * inv2d;
19  }
int h
Definition: utils.h:81
int w
Definition: utils.h:81

Member Data Documentation

§ maxValue

float SampleFisherMatrix::maxValue
private

Definition at line 10 of file FisherMatrix.h.


The documentation for this class was generated from the following file: