QTrk
Classes | Functions
BeadFinder Namespace Reference

Classes

struct  Config
 
struct  Position
 

Functions

std::vector< PositionFind (ImageData *img, float *sample, Config *cfg)
 
std::vector< PositionFind (uint8_t *img, int pitch, int w, int h, int smpCornerX, int smpCornerY, Config *cfg)
 

Function Documentation

§ Find() [1/2]

std::vector< Position > BeadFinder::Find ( ImageData img,
float *  sample,
Config cfg 
)

Definition at line 168 of file BeadFinder.cpp.

169 {
170  typedef std::complex<float> pixelc_t;
171 
172  // Compute nearest power of two dimension
173  int w=NextPowerOf2(img->w);
174  int h=NextPowerOf2(img->h);
175 
176  // Convert to std::complex and copy the image in there (subtract mean first)
177  float mean = img->mean();
178  pixelc_t* cimg = new pixelc_t[w*h];
179  std::fill(cimg, cimg+w*h, pixelc_t());
180  for (int y=0;y<img->h;y++) {
181  for (int x=0;x<img->w;x++) {
182  cimg[y*w+x] = img->data[y*img->w+x]-mean;
183  }
184  }
185 
186  // Inplace 2D fft
187  FFT2D(cimg,w,h,false);
188 
189  // Create an image to put the sample in with size [w,h] as well
190  pixelc_t* smpimg = new pixelc_t[w*h];
191  std::fill(smpimg, smpimg+w*h, pixelc_t());
192  float smpmean = ImageData(sample,cfg->roi,cfg->roi).mean();
193  for (int y=0;y<cfg->roi;y++)
194  for (int x=0;x<cfg->roi;x++)
195  smpimg[ ((y-cfg->roi)&(h-1)) * w + ( (x-cfg->roi)&(w-1))] = sample[cfg->roi*y+x]-smpmean;
196 
197 // ComplexToJPEGFile("smpimg.jpg", smpimg, w,h);
198  FFT2D(smpimg,w,h,false);
199 
200  for (int i=0;i<w*h;i++)
201  cimg[i]*=smpimg[i];
202  FFT2D(cimg,w,h,true);
203 
204  float maxVal = 0.0f;
205  for (int i=0;i<w*h;i++)
206  maxVal=std::max(maxVal, cimg[i].real());
207 
208  std::vector<Position> pts;
209  for (int y=0;y<img->h;y++) {
210  for (int x=0;x<img->w;x++) {
211  if (cimg[y*w+x].real()>maxVal*cfg->similarity )
212  pts.push_back ( SearchArea(cimg, w, h, x,y, cfg->MinPixelDistance()) );
213  }
214  }
215  //ComplexToJPEGFile("result.jpg", cimg, w,h);
216  delete[] smpimg;
217  delete[] cimg;
218 
219  RecenterAndFilter(img, pts, cfg);
220 
221  return pts;
222 }
float MinPixelDistance()
Definition: BeadFinder.h:18
TImageData< float > ImageData
Definition: QueuedTracker.h:69
void RecenterAndFilter(ImageData *img, std::vector< Position > &pts, Config *cfg)
Definition: BeadFinder.cpp:104
Position SearchArea(std::complex< float > *cimg, int w, int h, int px, int py, int dist)
Definition: BeadFinder.cpp:76
T mean()
Definition: utils.h:102
int h
Definition: utils.h:81
int NextPowerOf2(int x)
Definition: BeadFinder.cpp:11
void FFT2D(std::complex< float > *d, int w, int h, bool inverse)
Definition: BeadFinder.cpp:44
T * data
Definition: utils.h:80
int w
Definition: utils.h:81

§ Find() [2/2]

std::vector< Position > BeadFinder::Find ( uint8_t *  img,
int  pitch,
int  w,
int  h,
int  smpCornerX,
int  smpCornerY,
BeadFinder::Config cfg 
)

Definition at line 224 of file BeadFinder.cpp.

225 {
226  ImageData fimg = ImageData::alloc(w,h);
227 
228  for (int y=0;y<h;y++)
229  for (int x=0;x<w;x++)
230  fimg.at(x,y) = img[y*pitch+x];
231 
232  float *fsmp = new float[cfg->roi*cfg->roi];
233  for (int y=0;y<cfg->roi;y++) {
234  for (int x=0;x<cfg->roi;x++) {
235  fsmp [y*cfg->roi+x] = fimg [ (y+smpCornerY) * h + x + smpCornerX ];
236  }
237  }
238 
239  std::vector<Position> beads = Find(&fimg, fsmp, cfg);
240 
241  delete[] fsmp;
242  fimg.free();
243  return beads;
244 }
std::vector< Position > Find(ImageData *img, float *sample, Config *cfg)
Definition: BeadFinder.cpp:168
static TImageData alloc(int w, int h)
Definition: utils.h:110
void free()
Definition: utils.h:111
T & at(int x, int y)
Definition: utils.h:96