spyrit.core.torch.center_pad

spyrit.core.torch.center_pad(img: tensor, out_shape: tuple, in_shape: tuple = None) tensor[source]

Pads an image to the specified shape by centering it.

Args:

img (torch.tensor): Image to pad. If the image is vectorized, the input shape must be specified.

out_shape (tuple): Shape of the output image after padding. Must be a tuple of two integers (height, width).

in_shape (tuple, optional): Shape of the input image, must be specified if and only if the input image is vectorized. Must be a tuple of two integers (height, width). If None, the input is supposed to be a 2D image. Defaults to None.

Returns:

torch.tensor: Padded image. It has the same number of dimensions as the input image.