Image Processing

pyfoamalgo.nanmean_image_data(*args, kept=None)

Compute nanmean of an array of images or a tuple/list of two images.

Parameters
  • args – One input which is a 2D or 3D array or two inputs which are both 2D arrays. If the input is a single 2D array, a copy will be returned. This seemingly awkward ‘feature’ is a sugar for having clean code in EXtra-foam in order to deal train- and pulse-resolved detectors at the same time.

  • kept (None/list) – Indices of the kept images. Ignored if args has more than one items.

Returns

nanmean of the input data.

Return type

numpy.ndarray.

pyfoamalgo.correct_image_data(data, *, gain=None, offset=None, intradark=False, detector='')

Apply gain and/or offset correct to image data.

Parameters
  • data (numpy.array) – image data, Shape = (y, x) or (indices, y, x)

  • gain (None/numpy.array) – Gain constants, which has the same shape as the image data.

  • offset (None/numpy.array) – Offset constants, which has the same shape as the image data.

  • intradark (bool) – Apply interleaved intra-dark correction after the gain/offset correction. In other words, for every other image in the array starting from the first one, it will be subtracted by the image next to it.

  • detector (str) – Detector name. If given, specialized correction may be applied. “DSSC” - change data pixels with value 0 to 256 before applying offset correction.

pyfoamalgo.mask_image_data(data, *, image_mask=None, threshold_mask=None, keep_nan=True, out=None)

Mask image data by image mask and/or threshold mask.

Parameters
  • data (numpy.ndarray) – Image data to be masked. Shape = (y, x) or (indices, y, x)

  • image_mask (numpy.ndarray) – Image mask. If provided, it must have the same shape as a single image, and the type must be bool. Shape = (y, x)

  • threshold_mask (tuple/None) – (min, max) of the threshold mask.

  • keep_nan (bool) – True for masking all pixels in nan and False for masking all pixels to zero.

  • out (numpy.ndarray) – Optional output array in which to mark the union of all pixels being masked. The default is None; if provided, it must have the same shape as the image, and the dtype must be bool. Only available if the image data is a 2D array. Shape = (y, x)