pytomography.transforms.SPECT.psf
#
Module Contents#
Classes#
Base class for all neural network modules. |
|
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
Base class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will have their parameters converted too when you call
to()
, etc.Note
As per the example above, an
__init__()
call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- 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)[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.- Parameters:
psf_meta (SPECTPSFMeta) – Metadata corresponding to the parameters of PSF blurring
- configure(object_meta, image_meta)[source]#
Function used to initalize the transform using corresponding object and image metadata
- Parameters:
object_meta (SPECTObjectMeta) – Object metadata.
image_meta (SPECTImageMeta) – Image 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 image 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 image 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