ess.imaging.tools.analysis.resize#

ess.imaging.tools.analysis.resize(image, sizes, method='sum')[source]#

Resize an image by folding it into blocks of specified sizes and applying a reduction method. The sizes should be provided as a dictionary where the keys are dimension names and the values are the sizes of the blocks. The shape of the input image must be divisible by the block sizes.

Parameters:
  • image (Variable | DataArray) – The image to resample.

  • sizes (dict[str, int]) – A dictionary specifying the desired size of the output image for each dimension. The original sizes should be divisible by the specified sizes. For example, {'x': 128, 'y': 128} will create an output image of size 128x128. Any dimensions with same sizes to the resizing image will be ignored. If the output image sizes will be same as the input image sizes, it will not apply the method and return a copy of the input image.

  • method (str | Callable, default: 'sum') – The reduction method to apply to the blocks. This can be a string referring to any valid Scipp reduction method, such as ‘sum’, ‘mean’, ‘max’, etc. Alternatively, a custom reduction function can be provided. The function signature should accept a scipp.Variable or scipp.DataArray as first argument and a set of dimensions to reduce over as second argument. The function should return a scipp.Variable or scipp.DataArray.

Return type:

Variable | DataArray

Notes

If the image is a scipp.DataArray, bin edges in the resizing dimensions will be preserved if they are 1-dimensional and sorted. New bin edges will be chosen according to the resizing sizes. For other coordinates, new coordinates will be average values of each resized blocks.

Warning

The coordinates in the output may not be correct if they are not sorted or not linear.