27 #ifndef __imCenterCircleSym_hpp__
28 #define __imCenterCircleSym_hpp__
30 #include "../math/vectorUtils.hpp"
31 #include "../math/fit/fitGaussian.hpp"
50 template<
typename realT>
82 init( 5, 0.1, 1.0, 20.0, 1.0);
119 if(
mask->rows() == im.rows() &&
mask->cols() == im.cols()) doMask =
true;
129 std::vector< std::vector<realT> > rads;
134 realT startX, startY;
138 for(
int i =0; i<N; ++i)
141 for(
int j=0; j<N;++j)
145 for(
int k =0;
k< rads.size(); ++
k)
150 for(
int ii = startX -
maxRad; ii <= startX+
maxRad; ++ii)
152 for(
int jj = startY -
maxRad; jj <= startY+
maxRad; ++jj)
157 if( (*
mask)(ii,jj) == 0)
continue;
161 rad = sqrt(pow( ii-startX, 2) + pow( jj-startY,2));
163 if(rad < minRad || rad >=
maxRad)
continue;
165 rads[ (rad-
minRad)/
dRad ].push_back( im(ii,jj) );
172 for(
int k =0;
k< rads.size(); ++
k)
174 if(rads[
k].size() <= 1)
continue;
178 grid(i,j) += var/pow(mean,2);
200 realT
mx, mn, gx, gy;
229 template<
typename iosT,
char comment='#'>
232 char c[] = {comment,
'\0'};
234 ios <<
c <<
"--------------------------------------\n";
235 ios <<
c <<
"mx::improc::imCenterCircleSym Results \n";
236 ios <<
c <<
"--------------------------------------\n";
239 ios <<
c <<
"Cost half-width: " << 0.5*
sigma2fwhm( sqrt( pow(
fit.sigma_x(),2) + pow(
fit.sigma_y(),2)) *
dPix) <<
" pixels\n";
240 ios <<
c <<
"--------------------------------------\n";
241 ios <<
c <<
"Setup:\n";
242 ios <<
c <<
"--------------------------------------\n";
243 ios <<
c <<
"maxPix: " <<
maxPix <<
"\n";
244 ios <<
c <<
"dPix: " <<
dPix <<
"\n";
245 ios <<
c <<
"minRad: " <<
minRad <<
"\n";
246 ios <<
c <<
"maxRad: " <<
maxRad <<
"\n";
247 ios <<
c <<
"dRad: " <<
dRad <<
"\n";
248 ios <<
c <<
"smWidth: " <<
smWidth <<
"\n";
250 ios <<
c <<
"--------------------------------------\n";
251 ios <<
c <<
"Fit results:\n" ;
253 ios <<
c <<
"--------------------------------------\n";
263 template<
char comment ='#'>
266 return dumpResults<std::ostream, comment>(std::cout);
Class to manage fitting a 2D Gaussian to data via the levmarInterface.
Tools for using the eigen library for image processing.
constexpr units::realT c()
The speed of light.
constexpr units::realT k()
Boltzmann Constant.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
floatT sigma2fwhm(floatT sig)
Convert from Gaussian width parameter to FWHM.
void filterImage(imageOutT &fim, imageInT im, kernelT kernel, int maxr=0)
Filter an image with a mean kernel.
valueT vectorMean(const valueT *vec, size_t sz)
Calculate the mean of a vector.
valueT vectorVariance(const valueT *vec, size_t sz, valueT mean)
Calculate the variance of a vector relative to a supplied mean value.
Image filters (smoothing, radial profiles, etc.)
Symetric Gaussian smoothing kernel.
Find the center of the image of a point source using circular symmetry of the PSF.
realT minRad
The minimum radius to include in the cost function. Default: 1.0.
eigenImage< realT > grid
The cost grid.
realT _x0
Internal storage of the guess center position.
realT dRad
The spacing of the radii. Default: 1.0.
int init(realT maxP, realT dP, realT minR, realT maxR, realT dR)
Initialize the grid.
eigenImage< realT > smGrid
The smoothed cost grid.
eigenImage< realT > * mask
An optional pointer to a mask. If not NULL and the same size as the input image, any 0 pixels in this...
mx::math::fit::fitGaussian2Dgen< realT > fit
The fitter for finding the centroid of the grid. You can use this to inspect the details of the fit i...
realT _y0
Internal storage of the guess center position.
realT dPix
The spacing of the points in the grid search. Default: 0.1.
realT smWidth
FWHM of the Guassian smoothing kernel. Default is 10 (seems to work well regardless of dPix)....
iosT & dumpResults(iosT &ios)
Output the results to a stream.
std::ostream & dumpResults()
Output the results to std::cout.
int center(realT &x, realT &y, eigenImage< realT > &im, realT x0, realT y0)
Peform the grid search and fit.
realT maxRad
The maximum radius to include in the cost function Default: 20.0.
realT maxPix
The maximum range of the grid search, the grid will be +/- maxPix. Default: 5.0.
realT guessWidth
Guess in original pixels for the FWHM of the cost grid. Default is 0.5, which seems to work well in m...