Source code for pytomography.projections.system_matrix

from __future__ import annotations
import abc
import torch
from pytomography.transforms import Transform
from pytomography.metadata import ObjectMeta, ImageMeta

[docs]class SystemMatrix(): r"""Abstract class for a general system matrix :math:`H:\mathbb{U} \to \mathbb{V}` which takes in an object :math:`f \in \mathbb{U}` and maps it to a corresponding image :math:`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 :math:`H:\mathbb{U} \to \mathbb{V}` through the ``forward`` method, it also implements :math:`H^T:\mathbb{V} \to \mathbb{U}` through the `backward` method, required during iterative reconstruction algorithms such as OSEM. Args: 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. """ def __init__( self, obj2obj_transforms: list[Transform], im2im_transforms: list[Transform], object_meta: ObjectMeta, image_meta: ImageMeta, ) -> None: self.obj2obj_transforms = obj2obj_transforms self.im2im_transforms = im2im_transforms self.object_meta = object_meta self.image_meta = image_meta self.initialize_transforms()
[docs] def initialize_transforms(self): """Initializes all transforms used to build the system matrix """ for transform in self.obj2obj_transforms: transform.configure(self.object_meta, self.image_meta) for transform in self.im2im_transforms: transform.configure(self.object_meta, self.image_meta)
@abc.abstractmethod
[docs] def forward(self, object: torch.tensor, **kwargs): r"""Implements forward projection :math:`Hf` on an object :math:`f`. Args: 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 :math:`j` in formula above) when back projecting. Useful for ordered-subset reconstructions. Defaults to None, which assumes all angles are used. Returns: torch.tensor[batch_size, Ltheta, Lx, Lz]: Forward projected image where Ltheta is specified by `self.image_meta` and `angle_subset`. """ ...
@abc.abstractmethod
[docs] def backward( self, image: torch.tensor, angle_subset: list | None = None, return_norm_constant: bool = False, ) -> torch.tensor: r"""Implements back projection :math:`H^T g` on an image :math:`g`. Args: 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 :math:`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 :math:`1/\sum_j H_{ij}` along with back projection. Defaults to 'False'. Returns: torch.tensor[batch_size, Lr, Lr, Lz]: the object obtained from back projection. """ ...