27#ifndef fitEmpirical_hpp
28#define fitEmpirical_hpp
43template <
typename realT>
47template <
typename _realT>
48struct empirical2D_sym_fitter;
60template <
typename fitterT>
65 typedef typename fitterT::realT realT;
104 arr.scale( this->
p,
scale );
105 arr.dx( this->
p,
dx );
106 arr.dy( this->
p,
dy );
114 arr.setup( data, ref, weights );
116 this->
n = arr.m_nx * arr.m_ny;
133 return arr.scale( this->
p );
142 return arr.dx( this->
p );
151 return arr.dy( this->
p );
158template <
typename realT>
173 int m_scale_idx{ 0 };
186 if( ref->rows() !=
m_nx || ref->cols() !=
m_ny )
188 std::cerr <<
"ref and data not same size\n";
194 if( weights->rows() !=
m_nx || weights->cols() !=
m_ny )
196 std::cerr <<
"ref and data not same size\n";
209 setup( data, ref,
nullptr );
237 realT scale( realT *p )
239 if( m_scale_idx < 0 )
245 return p[m_scale_idx];
249 void scale( realT *p, realT nscale )
251 if( m_scale_idx < 0 )
257 p[m_scale_idx] = nscale;
273 void dx( realT *p, realT ndx )
297 void dy( realT *p, realT ndy )
319template <
typename _realT>
322 typedef _realT realT;
324 static const int nparams = 3;
326 static void func( realT *p, realT *hx,
int m,
int n,
void *adata )
334 realT scale = arr->scale( p );
335 realT dx = arr->dx( p );
336 realT dy = arr->dy( p );
344 for(
int cc = 0; cc < arr->
m_ny; ++cc )
346 for(
int rr = 0; rr < arr->
m_nx; ++rr )
357 for(
int cc = 0; cc < arr->
m_ny; ++cc )
359 for(
int rr = 0; rr < arr->
m_nx; ++rr )
373template <
typename realT>
Class to manage fitting a 2D Moffat to data via the levmarInterface.
void setArray(const improc::eigenImage< realT > *data, const improc::eigenImage< realT > *ref, const improc::eigenImage< realT > *weights)
Set the data aray.
void setArray(const improc::eigenImage< realT > *data, const improc::eigenImage< realT > *ref)
Set the data aray.
void setFixed(bool scale, bool dx, bool dy)
Set whether each parameter is fixed.
void setGuess(realT scale, realT dx, realT dy)
Set the initial guess for the empirical fit.
void allocate_params()
Allocate parameters array based on previous call to nParams.
realT * p
Parameter array. On input is the initial estimates. On output has the estimated solution.
int n
I: measurement vector dimension.
levmarInterface()
Default constructor.
void * adata
Pointer to possibly additional data, passed uninterpreted to func & jacf.
Tools for using the eigen library for image processing.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
mx::math::fit::fitEmpirical2DGen< mx::math::fit::empirical2D_fitter< realT > > fitEmpirical2D
Alias for the fitEmpirical2D type fitting the symmetric Moffat profile.
A c++ interface to the templatized levmar minimization routines..
Wrapper for a native array to pass to levmarInterface, with empirical function fit details.
const improc::eigenImage< realT > * m_ref
Pointer to the reference image to fit to the data.
void setFixed(bool scale, bool dx, bool dy)
Set whether each parameter is fixed.
const improc::eigenImage< realT > * m_weights
Pointer to the weight image.
improc::eigenImage< realT > m_refShifted
Working memory for the shifted reference image.
size_t m_nx
X dimension of the array.
const improc::eigenImage< realT > * m_data
Pointer to the data array.
size_t m_ny
Y dimension of the array.
levmarInterface fitter structure for 2D empirical functions.