mrpro.utils.pad_or_crop

mrpro.utils.pad_or_crop(data: Tensor, new_shape: Sequence[int] | Size, dim: None | Sequence[int] = None, mode: Literal['constant', 'replicate', 'circular'] = 'constant', value: float = 0.0) Tensor[source]

Change shape of data by center cropping or symmetric padding.

Parameters:
  • data (Tensor) – Data to pad or crop.

  • new_shape (Sequence[int] | Size) – Desired shape of data.

  • dim (None | Sequence[int], default: None) – Dimensions the new_shape corresponds to. None is interpreted as last len(new_shape) dimensions.

  • mode (Literal['constant', 'replicate', 'circular'], default: 'constant') – Mode for padding.

  • value (float, default: 0.0) – Value to use for padding.

Returns:

Data zero padded or cropped to shape.