slmsuite.holography.analysis.image_fit
- image_fit(images, grid_ravel=None, function=<function gaussian2d>, guess=None, plot=False)[source]
Fit each image in a stack of images to a 2D
function
.- Parameters
images (numpy.ndarray (image_count, height, width)) – An image or array of images to fit. A single image is interpreted correctly as
(1, h, w)
even if(h, w)
is passed.grid_ravel (2-tuple of array_like of reals (height * width)) – Raveled components of the meshgrid describing coordinates over the images.
function (lambda ((float, float), ... ) -> float) – Some fitfunction which accepts
(x,y)
coordinates as first argument. Defaults togaussian2d()
.guess (None OR numpy.ndarray (parameter_count, image_count)) –
If
guess
isNone
, will construct a guess based on thefunction
passed. Functions for which guesses are implemented include:If
guess
isNone
andfunction
does not have a guess implemented, no guess will be provided to the optimizer.If
guess
is anumpy.ndarray
, a slice of the array will be provided to the optimizer as a guess for the fit parameters for each image.
plot (bool) – Whether to create a plot for each fit.
show (bool) – Whether or not to call
matplotlib.pyplot.show()
after generating the plot.
- Returns
A matrix with the fit results. The first row contains the rsquared quality of each fit. The values in the remaining rows correspond to the parameters for the supplied fit function. Failed fits have an rsquared of
numpy.nan
and parameters are set to the provided or constructed guess ornumpy.nan
if no guess was provided or constructed.- Return type
numpy.ndarray (
result_count
,image_count
)- Raises
NotImplementedError – If the provided
function
does not have a guess implemented.