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 to gaussian2d().

  • guess (None OR True OR numpy.ndarray (image_count, parameter_count)) –

    • If guess is None or True, will construct a guess based on the function passed. Functions for which guesses are implemented include:

      • gaussian2d()

    • If guess is None and function does not have a guess implemented, no guess will be provided to the optimizer and the user will be warned.

    • If guess is True and function does not have a guess implemented, an error will be raised.

    • If guess is a numpy.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.nan and parameters are set to the provided or constructed guess or numpy.nan if no guess was provided or constructed; errors are set to numpy.nan.

Return type:

numpy.ndarray (image_count, result_count)

Raises:

NotImplementedError – If the provided function does not have a guess implemented.