slmsuite.holography.analysis.image_variances

image_variances(images, centers=None, normalize=True, nansum=False)[source]

Computes the three second order central moments, equivalent to variance, for a stack of images. Specifically, this function returns a stack of the moments \(M_{20}\) and \(M_{02}\), along with \(M_{11}\), which are the variance in the \(x\) and \(y\) directions, along with the so-called shear variance. Recall that variance defined as

\[(\Delta x)^2 = \left<(x - \left<x\right>)^2\right>.\]

This equation is made central by subtraction of \(\left<x\right>\). The user can of course use take_moment() directly to access the non-central moments; this function is a helper to access useful quantities for analysis of spot size and skewness.

Parameters
  • images (numpy.ndarray) – A matrix in the style of the output of take(), with shape (image_count, h, w), where (h, w) is the width and height of the 2D images and image_count is the number of images. A single image is interpreted correctly as (1, h, w) even if (h, w) is passed.

  • centers (numpy.ndarray OR None) – If the user has already computed \(\left<x\right>\), for example via image_positions(), then this can be passed though centers. The default None computes centers internally.

  • normalize (bool) – Whether to normalize images. If False, normalization is assumed to have been precomputed.

  • nansum (bool) – Whether to use numpy.nansum() in place of numpy.sum().

Returns

Stack of \(M_{20}\), \(M_{02}\), and \(M_{11}\). Shape (3, image_count).

Return type

numpy.ndarray