pytomography.transforms.SPECT.psf
#
Module Contents#
Classes#
Network used to apply Gaussian blurring to each plane parallel to the detector head. The typical network used for low/medium energy SPECT PSF modeling. |
|
Network used to apply an arbitrary PSF based on the kernel_f function, which should be a function of parallel directions \(x\) and \(y\) and perpendicular direction \(d\) to the detector head |
|
obj2obj transform used to model the effects of PSF blurring in SPECT. The smoothing kernel used to apply PSF modeling uses a Gaussian kernel with width \(\sigma\) dependent on the distance of the point to the detector; that information is specified in the |
Functions#
|
Creates a 1D convolutional layer that is used for PSF modeling. |
- class pytomography.transforms.SPECT.psf.GaussianBlurNet(layer_r, layer_z=None)[source]#
Bases:
torch.nn.Module
Network used to apply Gaussian blurring to each plane parallel to the detector head. The typical network used for low/medium energy SPECT PSF modeling.
- Parameters:
layer_r (nn.Conv1d) – Kernel used for blurring in radial direction
layer_z (nn.Conv1d | None) – Kernel used for blurring in sup/inf direction.
- forward(input)[source]#
Applies PSF blurring to input. Each X-plane gets a different blurring kernel applied, depending on detector distance.
- Parameters:
input (torch.tensor) – Object to apply Gaussian blurring to
- Returns:
Blurred object, adjusted such that subsequent summation along the x-axis models the CDR
- Return type:
torch.tensor
- class pytomography.transforms.SPECT.psf.ArbitraryPSFNet(kernel_f, distances, kernel_size, dr)[source]#
Bases:
torch.nn.Module
Network used to apply an arbitrary PSF based on the kernel_f function, which should be a function of parallel directions \(x\) and \(y\) and perpendicular direction \(d\) to the detector head
- Parameters:
kernel_f (Callable) – PSF kernel
distances (Sequence[float]) – Distances corresponding to each plane parallel to the detector
kernel_size (int) – Size of kernel used for blurring. Should be large enough to encapsulate the entire PSF at all distances
dr (Sequence[float]) – The \(x\) and \(y\) voxel spacing in the object
- forward(input)[source]#
Applies PSF blurring to input. Each X-plane gets a different blurring kernel applied, depending on detector distance.
- Parameters:
input (torch.tensor) – Object to apply blurring to
- Returns:
Blurred object, adjusted such that subsequent summation along the x-axis models the CDR
- Return type:
torch.tensor
- pytomography.transforms.SPECT.psf.get_1D_PSF_layer(sigmas, kernel_size)[source]#
Creates a 1D convolutional layer that is used for PSF modeling.
- Parameters:
sigmas (array) – Array of length Lx corresponding to blurring (sigma of Gaussian) as a function of distance from scanner
kernel_size (int) – Size of the kernel used in each layer. Needs to be large enough to cover most of Gaussian
- Returns:
Convolutional neural network layer used to apply blurring to objects of shape [Lx, L1, L2] where Lx is treated as a batch size, L1 as the channel (or group index) and L2 is the axis being blurred over
- Return type:
torch.nn.Conv2d
- class pytomography.transforms.SPECT.psf.SPECTPSFTransform(psf_meta=None, kernel_f=None, psf_net=None)[source]#
Bases:
pytomography.transforms.Transform
obj2obj transform used to model the effects of PSF blurring in SPECT. The smoothing kernel used to apply PSF modeling uses a Gaussian kernel with width \(\sigma\) dependent on the distance of the point to the detector; that information is specified in the
SPECTPSFMeta
parameter. There are a few potential arguments to initialize this transform (i) psf_meta, which contains relevant collimator information to obtain a Gaussian PSF model that works for low/medium energy SPECT (ii) kernel_f, an callable function that gives the kernel at any source-detector distance \(d\), or (iii) psf_net, a network configured to automatically apply full PSF modeling to a given object \(f\) at all source-detector distances. Only one of the arguments should be given.- Parameters:
psf_meta (SPECTPSFMeta) – Metadata corresponding to the parameters of PSF blurring. In most cases (low/medium energy SPECT), this should be the only given argument.
kernel_f (Callable) – Function \(PSF(x,y,d)\) that gives PSF at every source-detector distance \(d\). It should be able to take in 1D numpy arrays as its first two arguments, and a single argument for the final argument \(d\). The function should return a corresponding 2D PSF kernel.
psf_net (Callable) – Network that takes in an object \(f\) and applies all necessary PSF correction to return a new object \(\tilde{f}\) that is PSF corrected, such that subsequent summation along the x-axis accurately models the collimator detector response.
- _configure_gaussian_model()[source]#
Internal function to configure Gaussian modeling. This is called when psf_meta is given in initialization
- _configure_kernel_model()[source]#
Internal function to configure arbitrary kernel modeling. This is called when kernel_f is given in initialization
- _configure_manual_net()[source]#
Internal function to configure the PSF net. This is called when psf_net is given in initialization
- configure(object_meta, proj_meta)[source]#
Function used to initalize the transform using corresponding object and projection metadata
- Parameters:
object_meta (SPECTObjectMeta) – Object metadata.
proj_meta (SPECTProjMeta) – Projections metadata.
- Return type:
None
- _compute_kernel_size(radius, axis)[source]#
Function used to compute the kernel size used for PSF blurring. In particular, uses the
min_sigmas
attribute ofSPECTPSFMeta
to determine what the kernel size should be such that the kernel encompasses at leastmin_sigmas
at all points in the object.- Returns:
The corresponding kernel size used for PSF blurring.
- Return type:
int
- _get_sigma(radius)[source]#
Uses PSF Meta data information to get blurring \(\sigma\) as a function of distance from detector.
- Parameters:
radius (float) – The distance from the detector.
- Returns:
An array of length Lx corresponding to blurring at each point along the 1st axis in object space
- Return type:
array
- _apply_psf(object, ang_idx)[source]#
Applies PSF modeling to an object with corresponding angle indices
- Parameters:
object (torch.tensor) – Tensor of shape
[batch_size, Lx, Ly, Lz]
corresponding to object rotated at different anglesang_idx (Sequence[int]) – List of length
batch_size
corresponding to angle of each object in the batch
- Returns:
Object with PSF modeling applied
- Return type:
torch.tensor
- forward(object_i, ang_idx)[source]#
Applies the PSF transform \(A:\mathbb{U} \to \mathbb{U}\) for the situation where an object is being detector by a detector at the \(+x\) axis.
- Parameters:
object_i (torch.tensor) – Tensor of size [batch_size, Lx, Ly, Lz] being projected along its first axis
ang_idx (int) – The projection indices: used to find the corresponding angle in projection space corresponding to each projection angle in
object_i
.
- Returns:
Tensor of size [batch_size, Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to n PSF corrected projection.
- Return type:
torch.tensor
- backward(object_i, ang_idx, norm_constant=None)[source]#
Applies the transpose of the PSF transform \(A^T:\mathbb{U} \to \mathbb{U}\) for the situation where an object is being detector by a detector at the \(+x\) axis. Since the PSF transform is a symmetric matrix, its implemtation is the same as the
forward
method.- Parameters:
object_i (torch.tensor) – Tensor of size [batch_size, Lx, Ly, Lz] being projected along its first axis
ang_idx (int) – The projection indices: used to find the corresponding angle in projection space corresponding to each projection angle in
object_i
.norm_constant (torch.tensor, optional) – A tensor used to normalize the output during back projection. Defaults to None.
- Returns:
Tensor of size [batch_size, Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to n PSF corrected projection.
- Return type:
torch.tensor