mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Utilities for working with the Gaussian function
Functions | |
template<typename floatT > | |
constexpr floatT | mx::math::func::twosqrt2log2 () |
Constant to convert between the Gaussian width parameter and FWHM. More... | |
template<typename floatT > | |
floatT | mx::math::func::fwhm2sigma (floatT fw) |
Convert from FWHM to the Gaussian width parameter. More... | |
template<typename floatT > | |
floatT | mx::math::func::sigma2fwhm (floatT sig) |
Convert from Gaussian width parameter to FWHM. More... | |
template<typename realT > | |
realT | mx::math::func::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. More... | |
template<typename realT > | |
realT | mx::math::func::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. More... | |
template<typename realT > | |
void | mx::math::func::gaussian2D (realT *arr, size_t nx, size_t ny, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma) |
Fill in an array with the 2D arbitrarily-centered symmetric Gaussian. More... | |
template<typename realT > | |
realT | mx::math::func::gaussian2D (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) |
Find value at position (x,y) of the 2D general elliptical Gaussian. More... | |
template<typename realT > | |
void | mx::math::func::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 ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) for the elliptical Gaussian. More... | |
template<typename realT > | |
void | mx::math::func::gaussian2D_rot2gen (realT &a, realT &b, realT &c, const realT sigma_x, const realT sigma_y, const realT theta) |
Convert from ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) to (a,b,c) for the elliptical Gaussian. More... | |
template<typename realT > | |
realT | mx::math::func::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. More... | |
template<typename realT > | |
void | mx::math::func::gaussian2D (realT *arr, size_t nx, size_t ny, const realT G0, const realT G, const realT x0, const realT y0, const realT a, const realT b, const realT c) |
Fill in an array with the 2D general elliptical Gaussian. More... | |
template<typename realT > | |
void | mx::math::func::gaussian2D_ang (realT *arr, size_t nx, size_t ny, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma_x, const realT sigma_y, const realT theta) |
Fill in an array with the 2D general elliptical Gaussian. More... | |
template<typename realT > | |
void | mx::math::func::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. More... | |
floatT mx::math::func::fwhm2sigma | ( | floatT | fw | ) |
Convert from FWHM to the Gaussian width parameter.
Performs the conversion:
\( \sigma = 2\sqrt{2\log2}FWHM \)
[in] | fw | the full-width at half maximum |
Definition at line 65 of file gaussian.hpp.
Referenced by mx::AO::influenceFunctionsGaussian().
realT mx::math::func::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.
Computes: \( G(x) = G_0 + G\exp[-(0.5/\sigma^2)((x-x_0)^2)]\)
realT | is the type to use for arithmetic |
[in] | x | is the x-position at which to evaluate the Gaussian |
[in] | G0 | is the constant to add to the Gaussian |
[in] | G | is the scaling factor (peak height = G-G0) |
[in] | x0 | is the x-coordinate of the center |
[in] | sigma | is the width of the Gaussian. |
Definition at line 100 of file gaussian.hpp.
References mx::astro::constants::G(), and mx::astro::constants::sigma().
realT mx::math::func::gaussian2D | ( | 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 | ||
) |
Find value at position (x,y) of the 2D general elliptical Gaussian.
Computes:
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
where, for a counter-clockwise rotation \( \theta \), we have
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
In this version the parameters are specified directly as (a,b,c), in particular avoiding the trig function calls. This should be much more efficient, and so this version should be used inside fitting routines, etc. However note that the matrix {a b}{b c} must be positive-definite otherwise infinities can result from the argument of the exponent being positive.
The functions gaussian2D_gen2rot() and gaussian2D_rot2gen() provide conversions from (a,b,c) to ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) and back. The function gaussian2D_ang() is a wrapper for this function, which instead accepts ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) as inputs.
realT | is the type to use for arithmetic |
[in] | x | the x-position at which to evaluate the Gaussian |
[in] | y | the y-positoin at which to evaluate the Gaussian |
[in] | G0 | the constant to add to the Gaussian |
[in] | G | the scaling factor (peak = G-G0) |
[in] | x0 | the x-coordinate of the center |
[in] | y0 | the y-coordinate of the center |
[in] | a | the first rotation and scaling factor |
[in] | b | the second rotation and scaling factor |
[in] | c | the third rotation and scaling factor |
Definition at line 203 of file gaussian.hpp.
References mx::astro::constants::c(), and mx::astro::constants::G().
realT mx::math::func::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.
Computes:
\[ f(x,y) = G_0 + G \exp[-(0.5/\sigma^2)((x-x_0)^2+(y-y_0)^2)] \]
realT | is the type to use for arithmetic |
[in] | x | the x-position at which to evaluate the Gaussian |
[in] | y | the y-positoin at which to evaluate the Gaussian |
[in] | G0 | the constant to add to the Gaussian |
[in] | G | the scaling factor (peak height is G-G0) |
[in] | x0 | the x-coordinate of the center |
[in] | y0 | the y-coordinate of the center |
[in] | sigma | the width of the Gaussian. |
Definition at line 127 of file gaussian.hpp.
References mx::astro::constants::G(), and mx::astro::constants::sigma().
void mx::math::func::gaussian2D | ( | realT * | arr, |
size_t | nx, | ||
size_t | ny, | ||
const realT | G0, | ||
const realT | G, | ||
const realT | x0, | ||
const realT | y0, | ||
const realT | a, | ||
const realT | b, | ||
const realT | c | ||
) |
Fill in an array with the 2D general elliptical Gaussian.
At each pixel (x,y) of the array this computes:
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
where, for a counter-clockwise rotation \( \theta \), we have
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
In this version the parameters are specified directly as (a,b,c), in particular avoiding the trig function calls. This should be much more efficient, and so this version should be used inside fitting routines, etc.
The functions gaussian2D_gen2rot() and gaussian2D_rot2gen() provide conversions from (a,b,c) to ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) and back. The function gaussian2D_ang() is a wrapper for this function, which instead accepts ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) as inputs.
realT | is the type to use for arithmetic |
[out] | arr | the native array to populate with the Gaussian function |
[in] | nx | the x-size of the array, in pixels |
[in] | ny | the y-size of the array, in pixels |
[in] | G0 | the constant to add to the Gaussian |
[in] | G | the scaling factor (peak = G) |
[in] | x0 | the x-coordinate of the center, in pixels |
[in] | y0 | the y-coordinate of the center, in pixels |
[in] | a | is the first rotation and scaling factor |
[in] | b | is the second rotation and scaling factor |
[in] | c | is the third rotation and scaling factor |
Definition at line 420 of file gaussian.hpp.
References mx::astro::constants::c(), and mx::astro::constants::G().
Referenced by mx::math::func::gaussian2D(), and mx::math::func::gaussian2D_ang().
void mx::math::func::gaussian2D | ( | realT * | arr, |
size_t | nx, | ||
size_t | ny, | ||
const realT | G0, | ||
const realT | G, | ||
const realT | x0, | ||
const realT | y0, | ||
const realT | sigma | ||
) |
Fill in an array with the 2D arbitrarily-centered symmetric Gaussian.
At each pixel (x,y) of the array this computes:
\( f(x,y) = G_0 + G\exp[-(0.5/\sigma^2)((x-x_0)^2+(y-y_0)^2)] \)
realT | is the type to use for arithmetic |
[out] | arr | is the allocated array to fill in |
[in] | nx | is the size of the x dimension of the array |
[in] | ny | is the size of the y dimension of the array |
[in] | G0 | is the constant to add to the Gaussian |
[in] | G | is the scaling factor (peak height = G-G0) |
[in] | x0 | is the x-coordinate of the center |
[in] | y0 | is the y-coordinate of the center |
[in] | sigma | is the third rotation and scaling factor |
Definition at line 150 of file gaussian.hpp.
References mx::astro::constants::G(), mx::math::func::gaussian2D(), and mx::astro::constants::sigma().
realT mx::math::func::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.
Computes: \( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
where, for a counter-clockwise rotation \( \theta \), we have
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
This is a convenience wrapper for the general elliptical Gaussian function gaussian2D(), where here (a,b,c) are first calculated from ( \(\sigma_x\), \(\sigma_y\), \(\theta\)). This will in general be slower due to the trig function calls, so the (a,b,c) version should be used most of the time.
The functions gaussian2D_gen2rot() and gaussian2D_rot2gen() provide conversions from (a,b,c) to ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) and back. The function gaussian2D_rot() is a wrapper for this function, which instead accepts ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) as inputs.
realT | is the type to use for arithmetic |
[in] | x | the x-position at which to evaluate the Gaussian |
[in] | y | the y-positoin at which to evaluate the Gaussian |
[in] | G0 | the constant to add to the Gaussian |
[in] | G | the scaling factor (peak height = G-G0) |
[in] | x0 | the x-coordinate of the center |
[in] | y0 | the y-coordinate of the center |
[in] | sigma_x | the width in the rotated x direction |
[in] | sigma_y | the width in the rotated y direction |
[in] | theta | the counter-clockwise rotation angle |
Definition at line 376 of file gaussian.hpp.
References mx::astro::constants::c(), mx::astro::constants::G(), mx::math::func::gaussian2D(), and mx::math::func::gaussian2D_rot2gen().
void mx::math::func::gaussian2D_ang | ( | realT * | arr, |
size_t | nx, | ||
size_t | ny, | ||
const realT | G0, | ||
const realT | G, | ||
const realT | x0, | ||
const realT | y0, | ||
const realT | sigma_x, | ||
const realT | sigma_y, | ||
const realT | theta | ||
) |
Fill in an array with the 2D general elliptical Gaussian.
At each pixel (x,y) of the array this computes:
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
where, for a counter-clockwise rotation \( \theta \), we have
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
This is a convenience wrapper for the general elliptical Gaussian function gaussian2D( realT *, size_t, size_t, const realT, const realT, const realT, const realT, const realT, const realT, const realT) , where here (a,b,c) are first calculated from ( \(\sigma_x\), \(\sigma_y\), \(\theta\)).
The functions gaussian2D_gen2rot() and gaussian2D_rot2gen() provide conversions from (a,b,c) to ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) and back.
realT | is the type to use for arithmetic |
[out] | arr | the native array to populate with the Gaussian function |
[in] | nx | the x-size of the array, in pixels |
[in] | ny | the y-size of the array, in pixels |
[in] | G0 | the constant to add to the Gaussian |
[in] | G | the scaling factor (peak = G) |
[in] | x0 | the x-coordinate of the center, in pixels |
[in] | y0 | the y-coordinate of the center, in pixels |
[in] | sigma_x | the width in the rotated x direction, in pixels |
[in] | sigma_y | the width in the rotated y direction, in pixels |
[in] | theta | the counter-clockwise rotation angle, in radians |
Definition at line 473 of file gaussian.hpp.
References mx::astro::constants::c(), mx::astro::constants::G(), mx::math::func::gaussian2D(), and mx::math::func::gaussian2D_rot2gen().
void mx::math::func::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 ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) for the elliptical Gaussian.
The general 2D elliptical Gaussian
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
can be expressed in terms of widths and a rotation angle using:
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
where \( \theta \) specifies a counter-clockwise rotation.
This function calculates ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) from inputs (a,b,c). It adopts the convention that the long axis of the ellipse is \(\sigma_x\), and \(\theta\) is chosen appropriately. Note that \(-\frac{\pi}{2} < \theta < \frac{\pi}{2}\).
realT | is the type to use for arithmetic |
[out] | sigma_x | the width parameter in the rotated x-direction |
[out] | sigma_y | the width parameter in the rotated y-direction |
[out] | theta | the c.c.w rotation |
[in] | a | the first rotation and scaling parameter |
[in] | b | the second rotation and scaling parameter |
[in] | c | the the third rotation and scaling parameter |
Definition at line 245 of file gaussian.hpp.
References mx::astro::constants::c().
void mx::math::func::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.
Given:
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
we calculate
\( \frac{\partial G}{\partial G_0} = 1 \)
\( \frac{\partial G}{\partial G} = (G - G_0)/A \)
\( \frac{\partial G}{\partial x_0} = 0.5(G-G_0)( 2a(x-x_0) + b(y-y_0)) \)
\( \frac{\partial G}{\partial y_0} = 0.5(G-G_0) ( b(x-x_0) + 2c(y-y_0)) \)
\( \frac{\partial G}{\partial a} = -0.5(G-G_0) ( (x-x_0)^2 ) \)
\( \frac{\partial G}{\partial b} = -0.5(G-G_0) ( (x-x_0)(y-y_0) ) \)
\( \frac{\partial G}{\partial c} = -0.5(G-G_0) ( (y-y_0)^2 )\)
j | is a 7 element vector which is populated with the derivatives |
x | is the x-position at which to evaluate the Gaussian |
y | is the y-positoin at which to evaluate the Gaussian |
G0 | is the constant to add to the Gaussian |
G | is the scaling factor (peak = A) |
x0 | is the x-coordinate of the center |
y0 | is the y-coordinate of the center |
a | is the first rotation and scaling factor |
b | is the second rotation and scaling factor |
c | is the third rotation and scaling factor |
realT | is the type to use for arithmetic |
Definition at line 535 of file gaussian.hpp.
References mx::astro::constants::c(), and mx::astro::constants::G().
void mx::math::func::gaussian2D_rot2gen | ( | realT & | a, |
realT & | b, | ||
realT & | c, | ||
const realT | sigma_x, | ||
const realT | sigma_y, | ||
const realT | theta | ||
) |
Convert from ( \(\sigma_x\), \(\sigma_y\), \(\theta\)) to (a,b,c) for the elliptical Gaussian.
The general 2D elliptical Gaussian
\( f(x,y) = G_0 + G\exp [-0.5( a(x-x_0)^2 + b(x-x_0)(y-y_0) + c(y-y_0)^2 ]\)
can be expressed in terms of widths and a rotation angle using:
\( a = \frac{\cos^2 \theta}{\sigma_x^2} + \frac{\sin^2\theta}{\sigma_y^2}\)
\( b = \frac{\sin 2\theta}{2} \left(\frac{1}{\sigma_x^2} - \frac{1}{\sigma_y^2} \right)\)
\( c = \frac{\sin^2 \theta}{\sigma_x^2} + \frac{\cos^2\theta}{\sigma_y^2}\)
where \( \theta \) specifies a counter-clockwise rotation.
This function calculates (a,b,c) from inputs ( \(\sigma_x\), \(\sigma_y\), \(\theta\)).
realT | is the type to use for arithmetic |
[out] | a | the first rotation and scaling parameter |
[out] | b | the second rotation and scaling parameter |
[out] | c | the the third rotation and scaling parameter |
[in] | sigma_x | the width parameter in the rotated x-direction |
[in] | sigma_y | the width parameter in the rotated y-direction |
[in] | theta | the c.c.w rotation |
Definition at line 328 of file gaussian.hpp.
References mx::astro::constants::c().
Referenced by mx::math::func::gaussian2D_ang().
floatT mx::math::func::sigma2fwhm | ( | floatT | sig | ) |
Convert from Gaussian width parameter to FWHM.
Performs the conversion:
\( FWHM = 2\sqrt{2\log2}\sigma \)
[in] | sig | the Gaussian width parameter |
Definition at line 80 of file gaussian.hpp.
Referenced by mx::improc::imCenterCircleSym< realT >::dumpResults(), and mx::math::fit::fitGaussian2D< fitterT >::fwhm().
|
constexpr |
Constant to convert between the Gaussian width parameter and FWHM.
Used for
\( FWHM = 2\sqrt{2\log2}\sigma \)
This was calculated in long double precision.
Definition at line 50 of file gaussian.hpp.