GaussMLE.GaussFit
Overview
GaussMLE.GaussFit
— ModuleGaussFit
The GaussFit
module provides functions for fitting Gaussian models to a 2D box or a stack of 2D "boxes" of data.
The fitstack
function is the primary exported function of GaussMLE.jl. It takes in a 3D array containing the data to be fitted, a symbol indicating the type of Gaussian model to fit, and additional model-specific arguments required for fitting. It returns an array of fitted parameters for each 2D box and an array of uncertainties for each set of fitted parameters.
The fitstack
function also accepts optional keyword arguments for specifying a camera variance image and the top left corners of the boxes in relation to the variance image. These are used to implement a variance-weighted fit as described by Huang et al:
- Huang, F., Hartwich, T., Rivera-Molina, F. et al. "Video-rate nanoscopy using sCMOS camera–specific single-molecule localization algorithms." Nat Methods 10, 653–658 (2013). DOI: 10.1038/nmeth.2488
Exported Functions
fitstack
: Fit Gaussian models to each box in a stack of 2D "boxes" of data.
Notes
- Data and Variance image must be in units of photons (Poisson distributed).
API
GaussMLE.GaussFit.calclogL
GaussMLE.GaussFit.crlb!
GaussMLE.GaussFit.fitbox!
GaussMLE.GaussFit.fitstack
GaussMLE.GaussFit.calclogL
— MethodcalclogL(θ::GaussMLEParams{T}, box::AbstractArray{T}, args::GaussMLEArgs) where {T<:Real}
Calculate the log-likelihood of a Gaussian MLE fit for a given set of parameters and data.
Arguments
θ::GaussMLEParams{T}
: AGaussMLEParams
object containing the parameters of the Gaussian MLE fit.box::AbstractArray{T}
: AnAbstractArray
containing the data to fit.args::GaussMLEArgs
: AGaussMLEArgs
object containing additional arguments for the fit.
Returns
- logL: The log-likelihood of the fit.
GaussMLE.GaussFit.crlb!
— Methodcrlb!(Σ::GaussMLEΣ{T}, grad_pixel::AbstractArray{T}, θ::GaussMLEParams{T}, boxsize::Int, args::GaussMLEArgs)
Calculate the Cramer-Rao lower bound (CRLB) for a given set of parameters and data.
Arguments
Σ::GaussMLEΣ{T}
: AGaussMLEΣ
object to store the CRLB values.grad_pixel::AbstractArray{T}
: AnAbstractArray
to store the gradient values.θ::GaussMLEParams{T}
: AGaussMLEParams
object containing the parameters of the Gaussian MLE fit.boxsize::Int
: The size of the box to fit.args::GaussMLEArgs
: AGaussMLEArgs
object containing additional arguments for the fit.
GaussMLE.GaussFit.fitbox!
— Methodfitbox!(θ::GaussMLEParams{T}, Σ::GaussMLEΣ{T}, box::AbstractArray{T}, args::GaussMLEArgs,
varimage::Union{T,AbstractArray{T}}, boxcorners::Union{T,AbstractArray{T}};
maxiter::Int = 100) where {T<:Real}
Fits a Gaussian blob model using maximum likelihood estimation and Poisson noise model to a single 2D "box" of data.
Arguments
θ::GaussMLEParams{T}
: Initial parameters for the Gaussian MLE model.Σ::GaussMLEΣ{T}
: Container for the calculated Cramer-Rao Lower Bound (CRLB) and log likelihood.box::AbstractArray{T}
: 2D array containing the data to be fitted.args::GaussMLEArgs
: Additional arguments required for fitting.varimage::Union{T,AbstractArray{T}}
: Camera readnoise variance image, or a single variance for all pixels.boxcorners::Union{T,AbstractArray{T}}
: The corners of the box in the full image. Used whenvarimage
is an image.
Keyword Arguments
maxiter::Int
: Maximum number of iterations for the fitting process (default is 100).
Output
- Updates
θ
andΣ
in-place with the fitted parameters and their uncertainties.
Notes
- This function performs iterative fitting and stops either when the fit converges or when it reaches
maxiter
iterations. - The input
box
must be a square 2D array. - Input data
box
is assumed to be background subtracted.
GaussMLE.GaussFit.fitstack
— Methodfitstack(stack::AbstractArray{T}, modelsymbol::Symbol, args::GaussMLEArgs{T}; varimage::Union{T,AbstractArray{T}}=T(0), boxcorners::Union{T,AbstractArray{T}}=T(0)) where T <: Real
Fit Gaussian models to each box in a stack of 2D "boxes" of data.
Arguments
stack::AbstractArray{T}
: 3D array containing the data to be fitted. Each slice along the third dimension is treated as a separate 2D box.modelsymbol::Symbol
: Symbol indicating the type of Gaussian model to fit.args::GaussMLEArgs{T}
: Additional model-specific arguments required for fitting.
Keyword Arguments
varimage::Union{T,AbstractArray{T}}
: Camera variance image, or a single variance for all pixels (default isT(0)
).boxcorners::Union{T,AbstractArray{T}}
: The top left corners of the boxes in the variance image (default isT(0)
).
Returns
θ
: Array of fitted parameters for each 2D box.Σ
: Array of uncertainties for each set of fitted parameters.
Notes
- Data and Variance image must be in units of photons (Poisson distributed).
Example
fitstack(stack, :xynb, args; varimage=myvarimage, boxcorners=myboxcorners)