operator2d#
Module Contents#
Classes#
Base class for operators; operators are used to apply linear shift invariant operations to a sequence of 2D images. |
|
Operator that has been constructed using two other operators |
|
Operator that functions by rotating the input by a number of angles and applying a 1D convolution at each angle |
|
Operator that applies rotations followed by convolutions with two perpendicular 1D kernels (x/y) at each angle |
|
Operator built using a general 2D kernel; the output of this operator is 2D convolution with the Kernel2D instance |
|
Operator that uses a set of PSFs and distances to compute the output of the operator. The PSF is obtained by selecting the nearest PSF to each distance provided in __call__ so that each plane in input is convolved with the appropriate kernel. |
|
Gaussian operator; works by convolving the input with two perpendicular 1D kernels. This is implemented seperately from the Kernel2DOperator since it is more efficient to convolve with two 1D kernels than a 2D kernel. |
- class operator2d.Operator[source]#
Base class for operators; operators are used to apply linear shift invariant operations to a sequence of 2D images.
- __call__(input, xv, yv, a)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- _area(xv, yv)[source]#
Compute pixel volume in meshgrid
- Parameters:
xv (torch.Tensor) – Meshgrid x coordinates
yv (torch.Tensor) – Meshgrid y coordinates
- Returns:
Are
- Return type:
float
- set_device(device)[source]#
Sets the device of all parameters in the operator
- Parameters:
device (str) – Device to set parameters to
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the operator
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalization constant at each source-detector distance
- Return type:
torch.Tensor[Ld]
- normalize(input, xv, yv, a)[source]#
Normalizes the input by the normalization constant. This ensures that the operator maintains the total sum of the input at each source-detector distance.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input to be normalized
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalized input
- Return type:
torch.Tensor[Ld,Li,Lj]
- __add__(other)[source]#
Implementation of addition to allow for adding operators. Addition of two operators yields a new operator that corresponds to the sum of two linear operators
- class operator2d.CombinedOperator(func, operators, type)[source]#
Bases:
OperatorOperator that has been constructed using two other operators
- Parameters:
func (Callable) – Function that specifies how the two operators are combined
operators (Sequence[Operator]) – Sequence of operators
type (str) – Type of operator: either ‘sequential’ or ‘additive’
- set_device(device)[source]#
Sets the device of all the parameters in the composed operator
- Parameters:
device (str) – Device to set parameters to
- Return type:
None
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the combined operator using the normalization constants of its components
- Parameters:
xv (torch.Tensor) – Meshgrid x coordinates
yv (torch.Tensor) – Meshgrid y coordinates
a (torch.Tensor) – Source-detector distances
- Returns:
Normalization constant
- Return type:
torch.Tensor
- __call__(input, xv, yv, a, normalize=False)[source]#
Computes the output of the combined operator
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input to the operator
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool, optional) – Whether to normalize the output. Defaults to False.
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- class operator2d.Rotate1DConvOperator(kernel1D, N_angles, additive=False, use_fft_conv=False, rot=0)[source]#
Bases:
OperatorOperator that functions by rotating the input by a number of angles and applying a 1D convolution at each angle
- Parameters:
kernel1D (Kernel1D) – 1D kernel to apply at each rotation angle
N_angles (int) – Number of angles to convolve at. Evenly distributes these angles between 0 and 180 degrees (2 angles would be 0, 90 degrees)
additive (bool, optional) – Use in additive mode; in this case, the initial input is used at each rotation angle. If False, then output from each previous angle is used in succeeding angles. Defaults to False.
use_fft_conv (bool, optional) – Whether or not to use FFT based convolution. Defaults to False.
rot (float, optional) – Initial angle offset. Defaults to 0.
- _conv(input)[source]#
Applies convolution to the input
- Parameters:
input (torch.Tensor) – Input tensor
- Returns:
Convolved input tensor
- Return type:
torch.Tensor
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the operator
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalization constant at each source-detector distance
- Return type:
torch.Tensor[Ld]
- _rotate(input, angle)[source]#
Rotates the input at the desired angle
- Parameters:
input (torch.Tensor) – Input tensor
angle (float) – Angle to rotate by
- Returns:
Rotated input
- Return type:
torch.Tensor
- _apply_additive(input)[source]#
Applies the operator in additive mode
- Parameters:
input (torch.Tensor) – Input tensor
- Returns:
Output tensor, which is rotated + convolved input tensor
- Return type:
torch.Tensor
- _apply_regular(input)[source]#
Applies operator in non-additive mode
- Parameters:
input (torch.Tensor) – Input tensor
- Returns:
Output tensor, which is rotated + convolved input tensor
- Return type:
torch.Tensor
- __call__(input, xv, yv, a, normalize=False)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool) –
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- class operator2d.RotateSeperable2DConvOperator(kernel1D, N_angles, additive=False, use_fft_conv=False, rot=0)[source]#
Bases:
OperatorOperator that applies rotations followed by convolutions with two perpendicular 1D kernels (x/y) at each angle
- Parameters:
kernel1D (Kernel1D) – Kernel1D to use for convolution
N_angles (int) – Number of angles to rotate at
additive (bool, optional) – Use in additive mode; in this case, the initial input is used at each rotation angle. If False, then output from each previous angle is used in succeeding angles. Defaults to False.
use_fft_conv (bool, optional) – Whether or not to use FFT based convoltution. Defaults to False.
rot (float, optional) – Initial rotation angle. Defaults to 0.
- _conv(input)[source]#
Applies convolution
- Parameters:
input (torch.Tensor) – Input tensor to convole
- Returns:
Convolved input tensor
- Return type:
torch.Tensor
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the operator
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalization constant at each source-detector distance
- Return type:
torch.Tensor[Ld]
- _rotate(input, angle)[source]#
Applies rotation to input tensor
- Parameters:
input (torch.Tensor) – Input tensor to be rotated
angle (float) – Rotation angle
- Returns:
Rotated input tensor
- Return type:
torch.Tensor
- _apply_additive(input)[source]#
Applies operator in additive mode
- Parameters:
input (torch.Tensor) – Input tensor
- Returns:
Output tensor
- Return type:
torch.Tensor
- _apply_regular(input)[source]#
Applies operator in non-additive mode
- Parameters:
input (torch.Tensor) – Input tensor
- Returns:
Output tensor
- Return type:
torch.Tensor
- __call__(input, xv, yv, a, normalize=False)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool) –
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- class operator2d.Kernel2DOperator(kernel2D, use_fft_conv=False)[source]#
Bases:
OperatorOperator built using a general 2D kernel; the output of this operator is 2D convolution with the Kernel2D instance
- Parameters:
kernel2D (Kernel2D) – Kernel2D instance used for obtaining the generic 2D kernel
use_fft_conv (bool, optional) – Whether or not to use FFT based convolution. Defaults to False.
- _conv(input)[source]#
Applies convolution to the input
- Parameters:
input (torch.Tensor) – Input
- Returns:
Output
- Return type:
torch.Tensor
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the operator
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalization constant at each source-detector distance
- Return type:
torch.Tensor[Ld]
- __call__(input, xv, yv, a, normalize=False)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool) –
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- class operator2d.NearestKernelOperator(psf_data, distances, dr0, use_fft_conv=True, grid_sample_mode='bilinear')[source]#
Bases:
OperatorOperator that uses a set of PSFs and distances to compute the output of the operator. The PSF is obtained by selecting the nearest PSF to each distance provided in __call__ so that each plane in input is convolved with the appropriate kernel.
- Parameters:
psf_data (torch.Tensor[LD,LX,LY]) – Provided PSF data
distances (torch.Tensor[LD]) – Source-detector distance for each PSF
dr0 (float) – Spacing in the PSF data
use_fft_conv (bool, optional) – Whether or not to use FFT based convolutions. Defaults to True.
grid_sample_mode (str, optional) – How to sample the PSF when the input spacing is not the same as the PSF. Defaults to ‘bilinear’.
- set_device(device)[source]#
Sets the device of all parameters in the operator
- Parameters:
device (str) – Device to set parameters to
- Return type:
None
- _conv(input, kernel)[source]#
Performs convolution on the input data
- Parameters:
input (torch.Tensor) – Input data
kernel (torch.Tensor) – Kernel to convolve with
- Returns:
Convolved input data
- Return type:
torch.Tensor
- _get_nearest_distance_idxs(distances)[source]#
Obtains the indices of the nearest PSF to each distance
- Parameters:
distances (torch.Tensor) – Distances to find the nearest PSF for
- Returns:
Array of indices of the nearest PSF
- Return type:
torch.Tensor
- _get_kernel(xv, yv, a)[source]#
Obtains the kernel by sampling the nearest PSF at the appropriate location
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Kernel obtained by sampling the nearest PSF
- Return type:
torch.Tensor[Ld,Lx,Ly]
- __call__(input, xv, yv, a, normalize=False)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool) –
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]
- class operator2d.GaussianOperator(amplitude_fn, sigma_fn, amplitude_params, sigma_params, a_min=-torch.inf, a_max=torch.inf, use_fft_conv=False)[source]#
Bases:
OperatorGaussian operator; works by convolving the input with two perpendicular 1D kernels. This is implemented seperately from the Kernel2DOperator since it is more efficient to convolve with two 1D kernels than a 2D kernel.
- Parameters:
amplitude_fn (Callable) – Amplitude function for 1D Gaussian kernel
sigma_fn (Callable) – Scale function for 1D Gaussian kernel
amplitude_params (torch.Tensor) – Amplitude hyperparameters
sigma_params (torch.Tensor) – Scaling hyperparameters
a_min (float, optional) – Minimum source-detector distance for the kernel; any distance values passed to __call__ below this value will be clamped to this value. Defaults to -torch.inf.
a_max (float, optional) – Minimum source-detector distance for the kernel; any distance values passed to __call__ below this value will be clamped to this value. Defaults to torch.inf.
use_fft_conv (bool, optional) – Whether or not to use FFT based convolution. Defaults to False.
- normalization_constant(xv, yv, a)[source]#
Computes the normalization constant of the operator
- Parameters:
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
- Returns:
Normalization constant at each source-detector distance
- Return type:
torch.Tensor[Ld]
- _conv(input, kernel1D)[source]#
Performs convolution on input
- Parameters:
input (torch.Tensor) – Input tensor
kernel1D (torch.Tensor) – Gaussian 1D kernel
- Returns:
Output convolved tensor
- Return type:
torch.Tensor
- __call__(input, xv, yv, a, normalize=False)[source]#
Evaluates the operator on the input. The meshgrid xv and yv is used to compute the kernel size; it is assumed that the spacing in xv and yv is the same as that in input. The output is multiplied by the area of a pixel in the meshgrid.
- Parameters:
input (torch.Tensor[Ld,Li,Lj]) – Input 3D map to be operated on
xv (torch.Tensor[Lx,Ly]) – Meshgrid x coordinates
yv (torch.Tensor[Lx,Ly]) – Meshgrid y coordinates
a (torch.Tensor[Ld]) – Source-detector distances
normalize (bool) –
- Returns:
Output of the operator
- Return type:
torch.Tensor[Ld,Li,Lj]