pytomography.utils.spatial#

Module Contents#

Functions#

rotate_detector_z(x, angles[, mode, negative])

Returns an object tensor in a rotated reference frame such that the scanner is located at the +x axis. Note that the scanner angle \(\beta\) is related to \(\phi\) (azimuthal angle) by \(\phi = 3\pi/2 - \beta\).

compute_pad_size(width)

Computes the pad width required such that subsequent rotation retains the entire object

compute_pad_size_padded(width)

Computes the width by which an object was padded, given its padded size.

pad_object(object[, mode])

Pads object tensors by enough pixels in the xy plane so that subsequent rotations don't crop out any of the object

unpad_object(object)

Unpads a padded object tensor in the xy plane back to its original dimensions

pad_proj(proj[, mode, value])

Pads projections along the Lr axis

unpad_proj(proj)

Unpads the projections back to original Lr dimensions

pad_object_z(object, pad_size[, mode])

Pads an object tensor along z. Useful for PSF modeling

unpad_object_z(object, pad_size)

Unpads an object along the z dimension

pytomography.utils.spatial.rotate_detector_z(x, angles, mode='bilinear', negative=False)[source]#

Returns an object tensor in a rotated reference frame such that the scanner is located at the +x axis. Note that the scanner angle \(\beta\) is related to \(\phi\) (azimuthal angle) by \(\phi = 3\pi/2 - \beta\).

Parameters:
  • x (torch.tensor[batch_size, Lx, Ly, Lz]) – Tensor aligned with cartesian coordinate system specified

  • manual. (by the) –

  • angles (torch.Tensor) – The angles \(\beta\) where the scanner is located for each element in the batch x.

  • mode (str, optional) – Method of interpolation used to get rotated object. Defaults to bilinear.

  • negative (bool, optional) – If True, applies an inverse rotation. In this case, the tensor

:param x is an object in a coordinate system aligned with \(\beta\): :param and the function rotates the: :param x back to the original cartesian coordinate system specified by the users manual. In particular: :param if one: :param uses this function on a tensor with negative=False: :param then applies this function to that returned: :param tensor with negative=True: :param it should return the same tensor. Defaults to False.:

Returns:

Rotated tensor.

Return type:

torch.tensor[batch_size, Lx, Ly, Lz]

Parameters:
  • x (torch.Tensor) –

  • angles (torch.tensor) –

  • mode (str) –

  • negative (bool) –

pytomography.utils.spatial.compute_pad_size(width)[source]#

Computes the pad width required such that subsequent rotation retains the entire object

Parameters:

width (int) – width of the corresponding axis (i.e. number of elements in the dimension)

Returns:

the number of pixels by which the axis needs to be padded on each side

Return type:

int

pytomography.utils.spatial.compute_pad_size_padded(width)[source]#

Computes the width by which an object was padded, given its padded size.

Parameters:

width (int) – width of the corresponding axis (i.e. number of elements in the dimension)

Returns:

the number of pixels by which the object was padded to get to this width

Return type:

int

pytomography.utils.spatial.pad_object(object, mode='constant')[source]#

Pads object tensors by enough pixels in the xy plane so that subsequent rotations don’t crop out any of the object

Parameters:
  • object (torch.Tensor[batch_size, Lx, Ly, Lz]) – object tensor to be padded

  • mode (str, optional) – _description_. Defaults to ‘constant’.

Returns:

_description_

Return type:

_type_

pytomography.utils.spatial.unpad_object(object)[source]#

Unpads a padded object tensor in the xy plane back to its original dimensions

Parameters:

object (torch.Tensor[batch_size, Lx', Ly', Lz]) – padded object tensor

Returns:

Object tensor back to it’s original dimensions.

Return type:

torch.Tensor[batch_size, Lx, Ly, Lz]

pytomography.utils.spatial.pad_proj(proj, mode='constant', value=0)[source]#

Pads projections along the Lr axis

Parameters:
  • proj (torch.Tensor[batch_size, Ltheta, Lr, Lz]) – Projections tensor.

  • mode (str, optional) – Padding mode to use. Defaults to ‘constant’.

  • value (float, optional) – If padding mode is constant, fill with this value. Defaults to 0.

Returns:

Padded projections tensor.

Return type:

torch.Tensor[batch_size, Ltheta, Lr’, Lz]

pytomography.utils.spatial.unpad_proj(proj)[source]#

Unpads the projections back to original Lr dimensions

Parameters:

proj (torch.Tensor[batch_size, Ltheta, Lr', Lz]) – Padded projections tensor

Returns:

Unpadded projections tensor

Return type:

torch.Tensor[batch_size, Ltheta, Lr, Lz]

pytomography.utils.spatial.pad_object_z(object, pad_size, mode='constant')[source]#

Pads an object tensor along z. Useful for PSF modeling

Parameters:
  • object (torch.Tensor[batch_size, Lx, Ly, Lz]) – Object tensor

  • pad_size (int) – Amount by which to pad in -z and +z

  • mode (str, optional) – Padding mode. Defaults to ‘constant’.

Returns:

Padded object tensor along z.

Return type:

torch.Tensor[torch.Tensor[batch_size, Lx, Ly, Lz’]]

pytomography.utils.spatial.unpad_object_z(object, pad_size)[source]#

Unpads an object along the z dimension

Parameters:
  • object (torch.Tensor[batch_size, Lx, Ly, Lz']) – Padded object tensor along z.

  • pad_size (int) – Amount by which the padded tensor was padded in the z direcion

Returns:

Unpadded object tensor.

Return type:

torch.Tensor[batch_size, Lx, Ly, Lz]