pytomography.projections — PyTomography 0.8.0 documentation

Skip to main content
`Ctrl`+`K`

# `pytomography.projections`

This module contains classes/functionality for operators that map between distinct vector spaces. One (very important) operator of this form is the system matrix \(H:\mathbb{U} \to \mathbb{V}\), which maps from object space \(\mathbb{U}\) to image space \(\mathbb{V}\)

## Submodules

- `pytomography.projections.system_matrix`

## Package Contents

### Classes

`SystemMatrix` | Abstract class for a general system matrix \(H:\mathbb{U} \to \mathbb{V}\) which takes in an object \(f \in \mathbb{U}\) and maps it to a corresponding image \(g \in \mathbb{V}\) that would be produced by the imaging system. A system matrix consists of sequences of object-to-object and image-to-image transforms that model various characteristics of the imaging system, such as attenuation and blurring. While the class implements the operator \(H:\mathbb{U} \to \mathbb{V}\) through the `forward` method, it also implements \(H^T:\mathbb{V} \to \mathbb{U}\) through the backward method, required during iterative reconstruction algorithms such as OSEM.
`SPECTSystemMatrix` | System matrix for SPECT imaging. By default, this applies to parallel hole collimators, but appropriate use of im2im_transforms can allow this system matrix to also model converging/diverging collimator configurations as well.

class pytomography.projections.SystemMatrix(obj2obj_transforms, im2im_transforms, object_meta, image_meta)

  Abstract class for a general system matrix \(H:\mathbb{U} \to \mathbb{V}\) which takes in an object \(f \in \mathbb{U}\) and maps it to a corresponding image \(g \in \mathbb{V}\) that would be produced by the imaging system. A system matrix consists of sequences of object-to-object and image-to-image transforms that model various characteristics of the imaging system, such as attenuation and blurring. While the class implements the operator \(H:\mathbb{U} \to \mathbb{V}\) through the `forward` method, it also implements \(H^T:\mathbb{V} \to \mathbb{U}\) through the backward method, required during iterative reconstruction algorithms such as OSEM.

  Parameters:

    - obj2obj_transforms (Sequence[Transform]) – Sequence of object mappings that occur before forward projection.

    - im2im_transforms (Sequence[Transform]) – Sequence of image mappings that occur after forward projection.

    - object_meta (ObjectMeta) – Object metadata.

    - image_meta (ImageMeta) – Image metadata.

  initialize_transforms()

    Initializes all transforms used to build the system matrix

  abstract forward(object, **kwargs)

    Implements forward projection \(Hf\) on an object \(f\).

    Parameters:

      - object (torch.tensor[batch_size, Lx, Ly, Lz]) – The object to be forward projected

      - angle_subset (list, optional) – Only uses a subset of angles (i.e. only certain values of \(j\) in formula above) when back projecting. Useful for ordered-subset reconstructions. Defaults to None, which assumes all angles are used.

    Returns:

      Forward projected image where Ltheta is specified by self.image_meta and angle_subset.

    Return type:

      torch.tensor[batch_size, Ltheta, Lx, Lz]

  abstract backward(image, angle_subset=None, return_norm_constant=False)

    Implements back projection \(H^T g\) on an image \(g\).

    Parameters:

      - image (torch.Tensor) – image which is to be back projected

      - angle_subset (list, optional) – Only uses a subset of angles (i.e. only certain values of \(j\) in formula above) when back projecting. Useful for ordered-subset reconstructions. Defaults to None, which assumes all angles are used.

      - return_norm_constant (bool) – Whether or not to return \(1/\sum_j H_{ij}\) along with back projection. Defaults to ‘False’.

    Returns:

      the object obtained from back projection.

    Return type:

      torch.tensor[batch_size, Lr, Lr, Lz]

class pytomography.projections.SPECTSystemMatrix(obj2obj_transforms, im2im_transforms, object_meta, image_meta, n_parallel=1)

  Bases: `SystemMatrix`

  System matrix for SPECT imaging. By default, this applies to parallel hole collimators, but appropriate use of im2im_transforms can allow this system matrix to also model converging/diverging collimator configurations as well.

  Parameters:

    - obj2obj_transforms (Sequence[Transform]) – Sequence of object mappings that occur before forward projection.

    - im2im_transforms (Sequence[Transform]) – Sequence of image mappings that occur after forward projection.

    - object_meta (ObjectMeta) – Object metadata.

    - image_meta (ImageMeta) – Image metadata.

    - n_parallel (int) – Number of projections to use in parallel when applying transforms. More parallel events may speed up reconstruction time, but also increases GPU usage. Defaults to 1.

  forward(object, angle_subset=None)

    Applies forward projection to `object` for a SPECT imaging system.

    Parameters:

      - object (torch.tensor[batch_size, Lx, Ly, Lz]) – The object to be forward projected

      - angle_subset (list, optional) – Only uses a subset of angles (i.e. only certain values of \(j\) in formula above) when back projecting. Useful for ordered-subset reconstructions. Defaults to None, which assumes all angles are used.

    Returns:

      Forward projected image where Ltheta is specified by self.image_meta and angle_subset.

    Return type:

      torch.tensor[batch_size, Ltheta, Lx, Lz]

  backward(image, angle_subset=None, return_norm_constant=False)

    Applies back projection to `image` for a SPECT imaging system.

    Parameters:

      - image (torch.tensor[batch_size, Ltheta, Lr, Lz]) – image which is to be back projected

      - angle_subset (list, optional) – Only uses a subset of angles (i.e. only certain values of \(j\) in formula above) when back projecting. Useful for ordered-subset reconstructions. Defaults to None, which assumes all angles are used.

      - return_norm_constant (bool) – Whether or not to return \(1/\sum_j H_{ij}\) along with back projection. Defaults to ‘False’.

    Returns:

      the object obtained from back projection.

    Return type:

      torch.tensor[batch_size, Lr, Lr, Lz]