pytomography.algorithms.osem
#
This module contains classes that implement ordered-subset maximum liklihood iterative reconstruction algorithms. Such algorithms compute \(f_i^{n,m+1}\) from \(f_i^{n,m}\) where \(n\) is the index for an iteration, and \(m\) is the index for a subiteration (i.e. for a given subset). The notation is defined such that given \(M\) total subsets of equal size, \(f_i^{n+1,0} \equiv f_i^{n,M}\) (i.e. after completing a subiteration for each subset, we start the next iteration). Any class that inherits from this class must implement the forward
method. __init__
initializes the reconstruction algorithm with the image data \(g_j\), the forward and back projections used (i.e. networks to compute \(\sum_i H_{ij} a_i\) and \(\sum_j H_{ij} b_j\)), the initial object guess \(f_i^{0,0}\), the estimated scatter contribution \(s_j\), and the Bayesian Prior function \(V(f)\). Once the class is initialized, the number of iterations and subsets are specified at recon time when the forward
method is called.
Module Contents#
Classes#
Abstract class for different algorithms. The difference between subclasses of this class is the method by which they include prior information. If no prior function is used, they are all equivalent. |
|
Implements the ordered subset expectation algorithm using the one-step-late method to include prior information: \(f_i^{n,m+1} = \frac{f_i^{n,m}}{\sum_j H_{ij} + \beta \frac{\partial V}{\partial f_r}|_{f_i=f_i^{n,m}}} \sum_j H_{ij}\frac{g_j}{\sum_i H_{ij}f_i^{n,m}+s_j}\). |
|
Implements 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{f}_i^{n,m+1} = \frac{f_i^{n,m}}{\sum_j H_{ij}} \sum_j H_{ij}\frac{g_j^m}{\sum_i H_{ij}f_i^{n,m}+s_j}\) followed by \(f_i^{n,m+1} = \tilde{f}_i^{n,m+1} \left(1-\beta\frac{\alpha_n}{\sum_j H_{ij}}\frac{\partial V}{\partial \tilde{f}_i^{n,m+1}} \right)\). |
- class pytomography.algorithms.osem.OSML(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#
Abstract class for different algorithms. The difference between subclasses of this class is the method by which they include prior information. If no prior function is used, they are all equivalent.
- Parameters:
image (torch.tensor[batch_size, Lr, Ltheta, Lz]) – image data \(g_j\) to be reconstructed
object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f_i^{0,0}\) for the algorithm in object space
system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).
scatter (torch.tensor[batch_size, Lr, Ltheta, Lz]) – estimate of scatter contribution \(s_j\).
prior (Prior, optional) – the Bayesian prior; computes \(\beta \frac{\partial V}{\partial f_r}\). If
None
, then this term is 0. Defaults to None.
- get_subset_splits(n_subsets, n_angles)[source]#
Returns a list of arrays; each array contains indices, corresponding to projection numbers, that are used in ordered-subsets. For example,
get_subsets_splits(2, 6)
would return[[0,2,4],[1,3,5]]
.- Parameters:
n_subsets (int) – number of subsets used in OSEM
n_angles (int) – total number of projections
- Returns:
list of index arrays for each subset
- Return type:
list
- abstract __call__(n_iters, n_subsets, callbacks=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.
- Return type:
None
- class pytomography.algorithms.osem.OSEMOSL(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#
Bases:
OSML
Implements the ordered subset expectation algorithm using the one-step-late method to include prior information: \(f_i^{n,m+1} = \frac{f_i^{n,m}}{\sum_j H_{ij} + \beta \frac{\partial V}{\partial f_r}|_{f_i=f_i^{n,m}}} \sum_j H_{ij}\frac{g_j}{\sum_i H_{ij}f_i^{n,m}+s_j}\).
- Parameters:
image (torch.tensor[batch_size, Lr, Ltheta, Lz]) – image data \(g_j\) to be reconstructed
object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f_i^{0,0}\) for the algorithm in object space
system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).
scatter (torch.tensor[batch_size, Lr, Ltheta, Lz]) – estimate of scatter contribution \(s_j\).
prior (Prior, optional) – the Bayesian prior; computes \(\beta \frac{\partial V}{\partial f_r}\). If
None
, then this term is 0. Defaults to None.
- __call__(n_iters, n_subsets, callback=None, delta=1e-11)[source]#
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.
delta (float, optional) – Used to prevent division by zero when calculating ratio, defaults to 1e-11.
- Returns:
reconstructed object
- Return type:
torch.tensor[batch_size, Lx, Ly, Lz]
- class pytomography.algorithms.osem.OSEMBSR(image, system_matrix, object_initial=None, scatter=0, prior=None)[source]#
Bases:
OSML
Implements 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{f}_i^{n,m+1} = \frac{f_i^{n,m}}{\sum_j H_{ij}} \sum_j H_{ij}\frac{g_j^m}{\sum_i H_{ij}f_i^{n,m}+s_j}\) followed by \(f_i^{n,m+1} = \tilde{f}_i^{n,m+1} \left(1-\beta\frac{\alpha_n}{\sum_j H_{ij}}\frac{\partial V}{\partial \tilde{f}_i^{n,m+1}} \right)\).
- Parameters:
image (torch.tensor[batch_size, Lr, Ltheta, Lz]) – image data \(g_j\) to be reconstructed
object_initial (torch.tensor[batch_size, Lx, Ly, Lz]) – represents the initial object guess \(f_i^{0,0}\) for the algorithm in object space
system_matrix (SystemMatrix) – System matrix \(H\) used in \(g=Hf\).
scatter (torch.tensor[batch_size, Lr, Ltheta, Lz]) – estimate of scatter contribution \(s_j\).
prior (Prior, optional) – the Bayesian prior; computes \(\beta \frac{\partial V}{\partial f_r}\). If
None
, then this term is 0. Defaults to None.
- __call__(n_iters, n_subsets, relaxation_function=lambda x: ..., callback=None, delta=1e-11)[source]#
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.
delta (_type_, optional) – Used to prevent division by zero when calculating ratio, defaults to 1e-11.
- Returns:
reconstructed object
- Return type:
torch.tensor[batch_size, Lx, Ly, Lz]