pytomography.transforms.SPECT.psf — PyTomography 0.8.0 documentation

Skip to main content
`Ctrl`+`K`

# `pytomography.transforms.SPECT.psf`

## Module Contents

### Classes

`GaussianBlurNet` | Base class for all neural network modules.
`SPECTPSFTransform` | 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 `PSFMeta` parameter.

### Functions

`get_1D_PSF_layer`(sigmas, kernel_size) | Creates a 1D convolutional layer that is used for PSF modeling.

class pytomography.transforms.SPECT.psf.GaussianBlurNet(layer_r, layer_z=None)

  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.

  forward(input)

pytomography.transforms.SPECT.psf.get_1D_PSF_layer(sigmas, kernel_size)

  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 [batch_size, Lx, Ly, Lz]

  Return type:

    torch.nn.Conv2d

class pytomography.transforms.SPECT.psf.SPECTPSFTransform(psf_meta)

  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 `PSFMeta` parameter.

  Parameters:

    psf_meta (PSFMeta) – Metadata corresponding to the parameters of PSF blurring

  configure(object_meta, image_meta)

    Function used to initalize the transform using corresponding object and image metadata

    Parameters:

      - object_meta (ObjectMeta) – Object metadata.

      - image_meta (ImageMeta) – Image metadata.

    Return type:

      None

  compute_kernel_size(radius, axis)

    Function used to compute the kernel size used for PSF blurring. In particular, uses the `min_sigmas` attribute of `PSFMeta` to determine what the kernel size should be such that the kernel encompasses at least `min_sigmas` at all points in the object.

    Returns:

      The corresponding kernel size used for PSF blurring.

    Return type:

      int

  get_sigma(radius)

    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)
  forward(object_i, ang_idx)

    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)

    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