slmsuite.holography.analysis.image_fit#
- image_fit(images, grid=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 ((array_like, array_like) OR None) – Components of the meshgrid describing coordinates over the images. If
None, makes a grid with unit pitch centered on the images.function (lambda ((float, float), ... ) -> float) – Some fitfunction which accepts
(x,y)coordinates as first argument. Defaults togaussian2d().guess (None OR True OR numpy.ndarray (
image_count,parameter_count)) –If
guessisNoneorTrue, will construct a guess based on thefunctionpassed. Functions for which guesses are implemented include:gaussian2d()
If
guessisNoneandfunctiondoes not have a guess implemented, no guess will be provided to the optimizer and the user will be warned.If
guessisTrueandfunctiondoes not have a guess implemented, an error will be raised.If
guessis anumpy.ndarray, a column 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, then the errors for each of the parameters. Failed fits have an rsquared of
numpy.nanand parameters are set to the provided or constructed guess ornumpy.nanif no guess was provided or constructed; errors are set tonumpy.nan.- Return type:
numpy.ndarray (
image_count,result_count)- Raises:
NotImplementedError – If the provided
functiondoes not have a guess implemented.