pytomography.algorithms.statistical_iterative
#
This module contains classes that implement statistical iterative reconstruction algorithms.
Module Contents#
Classes#
Parent class for all statistical iterative algorithms. All child classes must implement the |
|
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}\). |
|
Implementation of the block-sequential-regularized (BSREM) reconstruction algorithm: \(\hat{f}^{n,m+1} = \hat{f}^{n,m} + \alpha_n D \left[H_m^T \left(\frac{g_m}{H_m \hat{f}^{n,m} + s} -1 \right) - \beta \nabla_{f^{n,m}} V \right]\). The implementation of this algorithm corresponds to Modified BSREM-II with \(U=\infty\), \(t=0\), and \(\epsilon=0\) (see https://ieeexplore.ieee.org/document/1207396). There is one difference in this implementation: rather than using FBP to get an initial estimate (as is done in the paper), a single iteration of OSEM is used; this initialization is required here due to the requirement for global scaling (see discussion on page 620 of paper). |
|
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}\). |
|
Implementation of the KEM reconstruction algorithm given by \(\hat{\alpha}^{n,m+1} = \left[\frac{1}{K^T H_m^T 1} K^T H_m^T \left(\frac{g_m}{H_m K \hat{\alpha}^{n,m}+s}\right)\right] \hat{\alpha}^{n,m}\) and where the final predicted object is \(\hat{f}^{n,m} = K \hat{\alpha}^{n,m}\). |
|
Implementation of the Deep Image Prior reconstruction technique (see https://ieeexplore.ieee.org/document/8581448). This reconstruction technique requires an instance of a user-defined |
- class pytomography.algorithms.statistical_iterative.StatisticalIterative(projections, system_matrix, object_initial=None, scatter=None, prior=None, precompute_normalization_factors=True, device=pytomography.device)[source]#
Parent class for all statistical iterative algorithms. All child classes must implement the
__call__
method to perform reconstruction.- Parameters:
projections (torch.Tensor) – photopeak window projection 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.precompute_normalization_factors (bool) –
device (str) – The device correpsonding to the tensors output by the system matrix. In some cases, although the system matrix implementation uses
pytomography.device
in its internal computation, it will output tensors on the CPU due to their size (such as in listmode PET). Defaults topytomography.device
.
- abstract _validate_projector(system_matrix)[source]#
Method implemented by child classes that checks if the system matrix implements the required methods for reconstruction.
- Parameters:
system_matrix (_type_) – _description_
- abstract __call__(n_iters, n_subsets, callback=None)[source]#
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.
callback (pytomography.callbacks.Callback | None) –
- Return type:
None
- class pytomography.algorithms.statistical_iterative.OSEMOSL(projections, system_matrix, object_initial=None, scatter=None, prior=None, precompute_normalization_factors=True, device=pytomography.device)[source]#
Bases:
StatisticalIterative
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:
projections (torch.Tensor) – photopeak window projection 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.precompute_normalization_factors (bool) –
device (str) – The device correpsonding to the tensors output by the system matrix. In some cases, although the system matrix implementation uses
pytomography.device
in its internal computation, it will output tensors on the CPU due to their size (such as in listmode PET). Defaults topytomography.device
.
- _validate_projector(system_matrix)[source]#
Checks that the required classes are implemented by the reconstruction algorithm
- Parameters:
system_matrix (SystemMatrix) – System matrix being used as projector in reconstruction algorithm
- _set_recon_name(n_iters, n_subsets)[source]#
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
- _compute_normalization_factors()[source]#
Computes normalization factors \(H_m^T 1\) for all subsets \(m\).
- __call__(n_iters, n_subsets, n_subset_specific=None, callback=None)[source]#
Performs the reconstruction using
n_iters
iterations andn_subsets
subsets.- Parameters:
n_iters (int) – Number of iterations
n_subsets (int) – Number of subsets
n_subset_specific (int) – Iterate only over the subset specified. Defaults to None
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.statistical_iterative.BSREM(projections, system_matrix, object_initial=None, scatter=0, prior=None, relaxation_function=lambda x: ..., scaling_matrix_type='subind_norm', precompute_normalization_factors=True, device=pytomography.device)[source]#
Bases:
StatisticalIterative
Implementation of the block-sequential-regularized (BSREM) reconstruction algorithm: \(\hat{f}^{n,m+1} = \hat{f}^{n,m} + \alpha_n D \left[H_m^T \left(\frac{g_m}{H_m \hat{f}^{n,m} + s} -1 \right) - \beta \nabla_{f^{n,m}} V \right]\). The implementation of this algorithm corresponds to Modified BSREM-II with \(U=\infty\), \(t=0\), and \(\epsilon=0\) (see https://ieeexplore.ieee.org/document/1207396). There is one difference in this implementation: rather than using FBP to get an initial estimate (as is done in the paper), a single iteration of OSEM is used; this initialization is required here due to the requirement for global scaling (see discussion on page 620 of paper).
- Parameters:
projections (torch.Tensor) – projection 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.relaxation_function (Callable, optional) – Sequence \(\alpha_n\) used for relaxation. Defaults to \(\alpha_n=1/(n+1)\).
scaling_matrix_type (str, optional) – The form of the scaling matrix \(D\) used. If
subind_norm
(sub-iteration independent + normalized), then \(D=\left(S_m/M \cdot H^T 1 \right)^{-1}\). Ifsubdep_norm
(sub-iteration dependent + normalized) then \(D = \left(H_m^T 1\right)^{-1}\). See section III.D in the paper above for a discussion on this.device (str) – The device correpsonding to the tensors output by the system matrix. In some cases, although the system matrix implementation uses
pytomography.device
in its internal computation, it will output tensors on the CPU due to their size (such as in listmode PET). Defaults topytomography.device
.precompute_normalization_factors (bool) –
- _validate_projector(system_matrix)[source]#
Checks that the required classes are implemented by the reconstruction algorithm
- Parameters:
system_matrix (SystemMatrix) – System matrix being used as projector in reconstruction algorithm
- _compute_normalization_factors()[source]#
Computes normalization factors \(H_m^T 1\) for all subsets \(m\).
- _set_recon_name(n_iters, n_subsets)[source]#
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
- _scale_prior_gradient(gradient)[source]#
Used to scale gradient to avoid divisional errors in null regions when using CutOffTransform
- Parameters:
gradient (torch.tensor) – Gradient returned by prior function
- Returns:
New gradient tensor where values are set to 0 outside the cutoff region.
- Return type:
torch.tensor
- __call__(n_iters, n_subsets, n_subset_specific=None, callback=None)[source]#
Performs the reconstruction using
n_iters
iterations andn_subsets
subsets.- Parameters:
n_iters (int) – Number of iterations
n_subsets (int) – Number of subsets
n_subset_specific (int) – Iterate only over the subset specified. Defaults to None
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.statistical_iterative.OSEM(projections, system_matrix, object_initial=None, scatter=0, precompute_normalization_factors=True, device=pytomography.device)[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:
projections (torch.Tensor) – photopeak window projection 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.
precompute_normalization_factors (bool) –
device (str) –
- _validate_projector(system_matrix)[source]#
Checks that the required classes are implemented by the reconstruction algorithm
- Parameters:
system_matrix (SystemMatrix) – System matrix being used as projector in reconstruction algorithm
- class pytomography.algorithms.statistical_iterative.KEM(projections, system_matrix, kem_transform, object_initial=None, scatter=0)[source]#
Bases:
OSEM
Implementation of the KEM reconstruction algorithm given by \(\hat{\alpha}^{n,m+1} = \left[\frac{1}{K^T H_m^T 1} K^T H_m^T \left(\frac{g_m}{H_m K \hat{\alpha}^{n,m}+s}\right)\right] \hat{\alpha}^{n,m}\) and where the final predicted object is \(\hat{f}^{n,m} = K \hat{\alpha}^{n,m}\).
- Parameters:
projections (torch.Tensor) – projection data \(g\) to be reconstructed
system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).
kem_transform (KEMTransform) – The transform corresponding to the matrix \(K\).
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\).
- _compute_callback(n_iter)[source]#
Computes callback for KEM transform; this is reimplemented here because the self.object_prediction corresponds to the \(\alpha\) value and not \(f\). As such, the KEMTransform needs to be applied before the object is input to the callback.
- Parameters:
n_iter (int) – _description_
- __call__(n_iters, n_subsets, callback=None)[source]#
Performs the reconstruction using
n_iters
iterations andn_subsets
subsets.- Parameters:
n_iters (int) – Number of iterations
n_subsets (int) – Number of subsets
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.statistical_iterative.DIPRecon(projections, system_matrix, prior_network, rho=0.003, scatter=0, precompute_normalization_factors=True, EM_algorithm=OSEM)[source]#
Bases:
StatisticalIterative
Implementation of the Deep Image Prior reconstruction technique (see https://ieeexplore.ieee.org/document/8581448). This reconstruction technique requires an instance of a user-defined
prior_network
that implements two functions: (i) afit
method that takes in anobject
(\(x\)) which the networkf(z;\theta)
is subsequently fit to, and (ii) apredict
function that returns the current network prediction \(f(z;\theta)\). For more details, see the Deep Image Prior tutorial.- Parameters:
projections (torch.tensor) – projection data \(g\) to be reconstructed
system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).
prior_network (nn.Module) – User defined prior network that implements the neural network
f(z;\theta)
rho (float, optional) – Value of \(\rho\) used in the optimization procedure. Defaults to 1.
scatter (torch.tensor | float, optional) – Projection space scatter estimate. Defaults to 0.
precompute_normalization_factors (bool, optional) – Whether to precompute \(H_m^T 1\) and store on GPU in the OSEM network before reconstruction. Defaults to True.
- _validate_projector(system_matrix)[source]#
Checks that the required classes are implemented by the reconstruction algorithm
- Parameters:
system_matrix (SystemMatrix) – System matrix being used as projector in reconstruction algorithm
- __call__(n_iters, subit1, n_subsets_osem=1, callback=None)[source]#
Implementation of Algorithm 1 in https://ieeexplore.ieee.org/document/8581448. This implementation gives the additional option to use ordered subsets. The quantity SubIt2 specified in the paper is controlled by the user-defined
prior_network
class.- Parameters:
n_iters (int) – Number of iterations (MaxIt in paper)
subit1 (int) – Number of OSEM iterations before retraining neural network (SubIt1 in paper)
n_subsets_osem (int, optional) – Number of subsets to use in OSEM reconstruction. Defaults to 1.
- Returns:
Reconstructed image
- Return type:
torch.Tensor