pytomography.utils.spatial
#
Module Contents#
Functions#
|
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\). |
|
Computes the pad width required such that subsequent rotation retains the entire image |
|
Computes the width by which an object was padded, given its padded size. |
|
Pads object tensors by enough pixels in the xy plane so that subsequent rotations don't crop out any of the object |
|
Unpads a padded object tensor in the xy plane back to its original dimensions |
|
Pads an image along the Lr axis |
|
Unpads the image back to original Lr dimensions |
|
Pads an object tensor along z. Useful for PSF modeling |
|
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 image. 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 image
- 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_image(image, mode='constant', value=0)[source]#
Pads an image along the Lr axis
- Parameters:
image (torch.Tensor[batch_size, Ltheta, Lr, Lz]) – Image 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 image tensor.
- Return type:
torch.Tensor[batch_size, Ltheta, Lr’, Lz]
- pytomography.utils.spatial.unpad_image(image)[source]#
Unpads the image back to original Lr dimensions
- Parameters:
image (torch.Tensor[batch_size, Ltheta, Lr', Lz]) – Padded image tensor
- Returns:
Unpadded image 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]