pytomography.utils.helper_functions
#
Module Contents#
Functions#
|
Reverse cumulative sum along the first axis of a tensor of shape [batch_size, Lx, Ly, Lz]. |
|
Returns an object tensor in a rotated reference frame such that the scanner is located at the +x axis. Note that the scanner angle $eta$ is related to $phi$ (azimuthal angle) by $phi = 3pi/2 - eta$. |
|
Given the radial distance to center of object space from the scanner, computes the distance |
|
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.helper_functions.rev_cumsum(x)#
Reverse cumulative sum along the first axis of a tensor of shape [batch_size, Lx, Ly, Lz]. since this is used with CT correction, the initial voxel only contributes 1/2.
- Parameters:
x (torch.tensor[batch_size,Lx,Ly,Lz]) – Tensor to be summed
- Returns:
The cumulatively summed tensor.
- Return type:
torch.tensor[batch_size, Lx, Ly, Lz]
- pytomography.utils.helper_functions.rotate_detector_z(x, angle, interpolation=InterpolationMode.BILINEAR, negative=False)#
Returns an object tensor in a rotated reference frame such that the scanner is located at the +x axis. Note that the scanner angle $eta$ is related to $phi$ (azimuthal angle) by $phi = 3pi/2 - eta$.
- Parameters:
x (torch.tensor[batch_size, Lx, Ly, Lz]) – Tensor aligned with cartesian coordinate system specified
manual. (by the) –
angle (float) – The angle $eta$ where the scanner is located.
interpolation (InterpolationMode, optional) – Method of interpolation used to get rotated image.
InterpolationMode.BILINEAR. (Defaults to) –
negative (bool, optional) – If True, applies an inverse rotation. In this case, the tensor
$eta$ (x is an object in a coordinate system aligned with) –
the (and the function rotates) –
particular (x back to the original cartesian coordinate system specified by the users manual. In) –
one (if) –
negative=False (uses this function on a tensor with) –
returned (then applies this function to that) –
negative=True (tensor with) –
False. (it should return the same tensor. Defaults to) –
- Returns:
Rotated tensor.
- Return type:
torch.tensor[batch_size, Lx, Ly, Lz]
- pytomography.utils.helper_functions.get_distance(Lx, r, dx)#
- Given the radial distance to center of object space from the scanner, computes the distance
between each parallel plane (i.e. (y-z plane)) and a detector located at +x. This function is used for point spread function (PSF) blurring where the amount of blurring depends on thedistance from the detector.
- Parameters:
Lx (int) – The number of y-z planes to compute the distance of
r (float) – The radial distance between the central y-z plane and the detector at +x.
dx (float) – The spacing between y-z planes in Euclidean distance.
- Returns:
An array of distances for each y-z plane to the detector.
- Return type:
np.array[Lx]
- pytomography.utils.helper_functions.compute_pad_size(width)#
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.helper_functions.compute_pad_size_padded(width)#
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.helper_functions.pad_object(object, mode='constant')#
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.helper_functions.unpad_object(object)#
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.helper_functions.pad_image(image, mode='constant', value=0)#
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.helper_functions.unpad_image(image)#
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.helper_functions.pad_object_z(object, pad_size, mode='constant')#
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.helper_functions.unpad_object_z(object, pad_size)#
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]