pytomography.algorithms#

This module contains all the available reconstruction algorithms in PyTomography

Submodules#

Package Contents#

Classes#

OSML

Parent class for all variants of ordered subset maximum liklihood algorithms. All child classes must implement the __call__ method to perform reconstruction.

OSEM

Implementation of the ordered subset expectation maximum algorithm \(\hat{f}^{n,m+1} = \left[\frac{1}{H_m^T 1} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\).

OSEMOSL

Implementation of the ordered subset expectation algorithm using the one-step-late method to include prior information: \(\hat{f}^{n,m+1} = \left[\frac{1}{H_m^T 1 + \beta \frac{\partial V}{\partial \hat{f}}|_{\hat{f}=\hat{f}^{n,m}}} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\).

OSEMBSR

Implementation of the ordered subset expectation algorithm using the block-sequential-regularized (BSREM) method to include prior information. In particular, each iteration consists of two steps: \(\tilde{\hat{f}}^{n,m+1} = \left[\frac{1}{H_m^T 1} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\) followed by \(\hat{f}^{n,m+1} = \tilde{\hat{f}}^{n,m+1} \left(1-\beta\frac{\alpha_n}{H_m^T 1}\frac{\partial V}{\partial \tilde{\hat{f}}^{n,m+1}} \right)\).

FilteredBackProjection

Implementation of filtered back projection reconstruction \(\hat{f} = \frac{\pi}{N_{\text{proj}}} \mathcal{R}^{-1}\mathcal{F}^{-1}\Pi\mathcal{F} g\) where \(N_{\text{proj}}\) is the number of projections, \(\mathcal{R}\) is the 3D radon transform, \(\mathcal{F}\) is the 2D Fourier transform (applied to each projection seperately), and \(\Pi\) is the filter applied in Fourier space, which is by default the ramp filter.

class pytomography.algorithms.OSML(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#

Parent class for all variants of ordered subset maximum liklihood algorithms. All child classes must implement the __call__ method to perform reconstruction.

Parameters:
  • image (torch.Tensor) – image data \(g\) to be reconstructed

  • system_matrix (SystemMatrix) – system matrix that models the imaging system. In particular, corresponds to \(H\) in \(g=Hf\).

  • object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – the initial object guess \(f^{0,0}\). If None, then initial guess consists of all 1s. Defaults to None.

  • scatter (torch.Tensor) – estimate of scatter contribution \(s\). Defaults to 0.

  • prior (Prior, optional) – the Bayesian prior; used to compute \(\beta \frac{\partial V}{\partial f}\). If None, then this term is 0. Defaults to None.

get_subset_splits(n_subsets)#

Returns a list of subsets (where each subset contains indicies corresponding to projections). For example, if the image consisted of 6 total projections, then get_subsets_splits(2) would return [[0,2,4],[1,3,5]].

Parameters:

n_subsets (int) – number of subsets used in OSEM

Returns:

list of index arrays for each subset

Return type:

list

abstract __call__(n_iters, n_subsets, callbacks=None)#

Abstract method for performing reconstruction: must be implemented by subclasses.

Parameters:
  • n_iters (int) – Number of iterations

  • n_subsets (int) – Number of subsets

  • callbacks (CallBack, optional) – CallBacks to be evaluated after each subiteration. Defaults to None.

Return type:

None

class pytomography.algorithms.OSEM(image, system_matrix, object_initial=None, scatter=0)[source]#

Bases: OSEMOSL

Implementation of the ordered subset expectation maximum algorithm \(\hat{f}^{n,m+1} = \left[\frac{1}{H_m^T 1} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\).

Parameters:
  • image (torch.Tensor) – image data \(g\) to be reconstructed

  • object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f^{0,0}\) for the algorithm in object space

  • system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).

  • scatter (torch.Tensor) – estimate of scatter contribution \(s\).

class pytomography.algorithms.OSEMOSL(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#

Bases: OSML

Implementation of the ordered subset expectation algorithm using the one-step-late method to include prior information: \(\hat{f}^{n,m+1} = \left[\frac{1}{H_m^T 1 + \beta \frac{\partial V}{\partial \hat{f}}|_{\hat{f}=\hat{f}^{n,m}}} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\).

Parameters:
  • image (torch.Tensor) – image data \(g\) to be reconstructed

  • system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).

  • object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f^{0,0}\) for the algorithm in object space

  • scatter (torch.Tensor) – estimate of scatter contribution \(s\).

  • prior (Prior, optional) – the Bayesian prior; computes \(\beta \frac{\partial V}{\partial f}\). If None, then this term is 0. Defaults to None.

_set_recon_name(n_iters, n_subsets)#

Set the unique identifier for the type of reconstruction performed. Useful when saving reconstructions to DICOM files

Parameters:
  • n_iters (int) – Number of iterations

  • n_subsets (int) – Number of subsets

__call__(n_iters, n_subsets, callback=None)#

Performs the reconstruction using n_iters iterations and n_subsets subsets.

Parameters:
  • n_iters (int) – Number of iterations

  • n_subsets (int) – Number of subsets

  • callback (CallBack, optional) – Callback function to be evaluated after each subiteration. Defaults to None.

Returns:

reconstructed object

Return type:

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

class pytomography.algorithms.OSEMBSR(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#

Bases: OSML

Implementation of the ordered subset expectation algorithm using the block-sequential-regularized (BSREM) method to include prior information. In particular, each iteration consists of two steps: \(\tilde{\hat{f}}^{n,m+1} = \left[\frac{1}{H_m^T 1} H_m^T \left(\frac{g_m}{H_m\hat{f}^{n,m}+s}\right)\right] \hat{f}^{n,m}\) followed by \(\hat{f}^{n,m+1} = \tilde{\hat{f}}^{n,m+1} \left(1-\beta\frac{\alpha_n}{H_m^T 1}\frac{\partial V}{\partial \tilde{\hat{f}}^{n,m+1}} \right)\).

Parameters:
  • image (torch.Tensor) – image data \(g\) to be reconstructed

  • object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f^{0,0}\) for the algorithm in object space

  • system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).

  • scatter (torch.Tensor) – estimate of scatter contribution \(s\).

  • prior (Prior, optional) – the Bayesian prior; computes \(\beta \frac{\partial V}{\partial f}\). If None, then this term is 0. Defaults to None.

_set_recon_name(n_iters, n_subsets)#

Set the unique identifier for the type of reconstruction performed. Useful for saving to DICOM files

Parameters:
  • n_iters (int) – Number of iterations

  • n_subsets (int) – Number of subsets

__call__(n_iters, n_subsets, relaxation_function=lambda x: ..., callback=None)#

Performs the reconstruction using n_iters iterations and n_subsets subsets.

Parameters:
  • n_iters (int) – Number of iterations

  • n_subsets (int) – Number of subsets

  • relaxation_function (function) – Specifies relaxation sequence \(\alpha_n\) where \(n\) is the iteration number. Defaults to \(\alpha_n=1\) for all \(n\).

  • callback (CallBack, optional) – Callback function to be called after each subiteration. Defaults to None.

Returns:

reconstructed object

Return type:

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

class pytomography.algorithms.FilteredBackProjection(image, angles, filter=None)[source]#

Implementation of filtered back projection reconstruction \(\hat{f} = \frac{\pi}{N_{\text{proj}}} \mathcal{R}^{-1}\mathcal{F}^{-1}\Pi\mathcal{F} g\) where \(N_{\text{proj}}\) is the number of projections, \(\mathcal{R}\) is the 3D radon transform, \(\mathcal{F}\) is the 2D Fourier transform (applied to each projection seperately), and \(\Pi\) is the filter applied in Fourier space, which is by default the ramp filter.

Parameters:
  • image (torch.Tensor) – image data \(g\) to be reconstructed

  • angles (Sequence) – Angles corresponding to each projection in the image/

  • filter (Callable, optional) – Additional Fourier space filter (applied after Ramp Filter) used during reconstruction.

__call__()#

Applies reconstruction

Returns:

Reconstructed object prediction

Return type:

torch.tensor