center_crop

Contents

center_crop#

pulserver.mrd.center_crop()[source]#

Crop the trailing axes of an image to a centred window.

Parameters:
  • image – NumPy or Torch array.

  • shape – Extent of each trailing axis to keep; leading axes pass through.

Returns:

A view of image. Along each axis the sample at index n // 2, the centre of a centred FFT of n samples, is at index size // 2 of the window.

Return type:

array

Raises:

ValueError – If shape has more axes than image, or an extent is not in 1..image.shape[axis].

Examples

>>> import numpy as np
>>> from pulserver.mrd import center_crop
>>> image = np.arange(2 * 8).reshape(2, 8)
>>> center_crop(image, (4,)).shape
(2, 4)
>>> center_crop(np.arange(8), (4,))
array([2, 3, 4, 5])