48template <
typename floatT>
51 return static_cast<floatT
>( 2.3548200450309493820231386529193992754947713787716 );
63template <
typename floatT>
78template <
typename floatT>
98template <
typename realT>
106 return G0 + G * exp( -(
static_cast<realT
>( 0.5 ) / ( sigma * sigma ) * ( ( ( x - x0 ) * ( x - x0 ) ) ) ) );
125template <
typename realT>
136 G * std::exp( -( 0.5 / ( sigma * sigma ) * ( ( ( x - x0 ) * ( x - x0 ) ) + ( ( y - y0 ) * ( y - y0 ) ) ) ) );
149template <
typename realT>
162 for(
size_t j = 0; j < ny; ++j )
164 for(
size_t i = 0; i < nx; ++i )
168 arr[idx] =
gaussian2D( (realT)i, (realT)j, G0, G, x0, y0, sigma );
203template <
typename realT>
218 return G0 + G * std::exp( -0.5 * ( a * dx * dx + 2. * b * dx * dy + c * dy * dy ) );
244template <
typename realT>
253 realT x1, x2, s, s2, theta0, theta1;
255 realT arg = a * a - 2 * a * c + 4 * b * b + c * c;
258 x2 = 0.5 * ( a + c );
264 x2 = 0.5 * ( a + c ) + 0.5 * sqrt( arg );
265 x1 = 0.5 * ( a + c ) - 0.5 * sqrt( arg );
269 sigma_x = sqrt( 1. / x1 );
270 sigma_y = sqrt( 1. / x2 );
280 s = ( a - x1 ) * ( a - x1 ) / ( b * b + ( a - x1 ) * ( a - x1 ) );
284 if( fabs( x1 - x2 ) < 1e-12 )
290 theta0 = 0.5 * asin( 2 * b / ( x1 - x2 ) );
291 theta1 = asin( sqrt( s ) );
294 if( std::signbit( theta0 ) == std::signbit( theta1 ) )
301 theta = asin( -sqrt( s ) );
326template <
typename realT>
335 realT sn, cs, sx2, sy2;
339 sx2 = sigma_x * sigma_x;
340 sy2 = sigma_y * sigma_y;
342 a = cs * cs / sx2 + sn * sn / sy2;
343 b = sn * cs * ( 1. / sx2 - 1. / sy2 );
344 c = sn * sn / sx2 + cs * cs / sy2;
374template <
typename realT>
390 return gaussian2D( x, y, G0, G, x0, y0, a, b, c );
418template <
typename realT>
433 for(
size_t j = 0; j < ny; ++j )
435 for(
size_t i = 0; i < nx; ++i )
439 arr[idx] =
gaussian2D( (realT)i, (realT)j, G0, G, x0, y0, a, b, c );
470template <
typename realT>
489 gaussian2D( arr, nx, ny, G0, G, x0, y0, a, b, c );
531template <
typename realT>
549 j[2] = 0.5 * G_G0 * ( 2 * a * ( x - x0 ) + b * ( y - y0 ) );
551 j[3] = 0.5 * G_G0 * ( b * ( x - x0 ) + 2 * c * ( y - y0 ) );
553 j[4] = -0.5 * G_G0 * ( ( x - x0 ) * ( x - x0 ) );
555 j[5] = -0.5 * G_G0 * ( ( x - x0 ) * ( y - y0 ) );
557 j[6] = -0.5 * G_G0 * ( ( y - y0 ) * ( y - y0 ) );
realT gaussian2D(const realT x, const realT y, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma)
Find value at position (x,y) of the 2D arbitrarily-centered symmetric Gaussian.
floatT sigma2fwhm(floatT sig)
Convert from Gaussian width parameter to FWHM.
floatT fwhm2sigma(floatT fw)
Convert from FWHM to the Gaussian width parameter.
realT gaussian2D_ang(const realT x, const realT y, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma_x, const realT sigma_y, const realT theta)
Find value at position (x,y) of the 2D rotated elliptical Gaussian.
realT gaussian(const realT x, const realT G0, const realT G, const realT x0, const realT sigma)
Find value at position (x) of the 1D arbitrarily-centered symmetric Gaussian.
void gaussian2D_gen2rot(realT &sigma_x, realT &sigma_y, realT &theta, const realT a, const realT b, const realT c)
Convert from (a,b,c) to ( , , ) for the elliptical Gaussian.
void gaussian2D_jacobian(realT *j, const realT x, const realT y, const realT G0, const realT G, const realT x0, const realT y0, const realT a, const realT b, const realT c)
Calculate the Jacobian at position (x,y) for the 2D general elliptical Gaussian.
constexpr floatT twosqrt2log2()
Constant to convert between the Gaussian width parameter and FWHM.
void gaussian2D_rot2gen(realT &a, realT &b, realT &c, const realT sigma_x, const realT sigma_y, const realT theta)
Convert from ( , , ) to (a,b,c) for the elliptical Gaussian.