pytomography.projectors.PET#
Submodules#
Package Contents#
Classes#
System matrix of PET list mode data. Forward projections corresponds to computing the expected counts along all LORs specified: in particular it approximates \(g_i = \int_{\text{LOR}_i} h(r) f(r) dr\) where index \(i\) corresponds to a particular detector pair and \(h(r)\) is a Gaussian function that incorporates time-of-flight information (\(h(r)=1\) for non-time-of-flight). The integral is approximated in the discrete object space using Joseph3D projections. In general, the system matrix implements two different projections, the quantity \(H\) which projects to LORs corresponding to all detected events, and the quantity \(\tilde{H}\) which projects to all valid LORs. The quantity \(H\) is used for standard forward/back projection, while \(\tilde{H}\) is used to compute the sensitivity image. |
|
System matrix for sinogram-based PET reconstruction. |
Functions#
|
Generates a sinogram system matrix from a listmode system matrix. This is used in the single scatter simulation algorithm. |
- class pytomography.projectors.PET.PETLMSystemMatrix(object_meta, proj_meta, obj2obj_transforms=[], attenuation_map=None, scale_projection_by_sensitivity=False, N_splits=1, FOV_scale_enabled=True, device=pytomography.device)[source]#
Bases:
pytomography.projectors.SystemMatrixSystem matrix of PET list mode data. Forward projections corresponds to computing the expected counts along all LORs specified: in particular it approximates \(g_i = \int_{\text{LOR}_i} h(r) f(r) dr\) where index \(i\) corresponds to a particular detector pair and \(h(r)\) is a Gaussian function that incorporates time-of-flight information (\(h(r)=1\) for non-time-of-flight). The integral is approximated in the discrete object space using Joseph3D projections. In general, the system matrix implements two different projections, the quantity \(H\) which projects to LORs corresponding to all detected events, and the quantity \(\tilde{H}\) which projects to all valid LORs. The quantity \(H\) is used for standard forward/back projection, while \(\tilde{H}\) is used to compute the sensitivity image.
- Parameters:
object_meta (SPECTObjectMeta) – Metadata of object space, containing information on voxel size and dimensions.
proj_meta (PETLMProjMeta) – PET listmode projection space metadata. This information contains the detector ID pairs of all detected events, as well as a scanner lookup table and time-of-flight metadata. In addition, this metadata contains all information regarding event weights, typically corresponding to the effects of attenuation \(\mu\) and \(\eta\).
obj2obj_transforms (Sequence[Transform]) – Object to object space transforms applied before forward projection and after back projection. These are typically used for PSF modeling in PET imaging.
attenuation_map (torch.tensor[float] | None, optional) – Attenuation map used for attenuation modeling. If provided, all weights will be scaled by detection probabilities derived from this map. Note that this scales on top of any weights provided in
proj_meta, so if attenuation is already accounted for there, this is not needed. Defaults to None.scale_projection_by_sensitivity (bool, optional) – Whether or not to scale the projections by \(\mu \eta\). This is not needed in reconstruction algorithms using a PoissonLogLikelihood. Defaults to False.
N_splits (int) – Splits up computation of forward/back projection to save GPU memory. Defaults to 1.
device (str) – The device on which forward/back projection tensors are output. This is seperate from
pytomography.device, which handles internal computations. The reason for having the option of a second device is that the projection space may be very large, and certain GPUs may not have enough memory to store the projections. Ifdeviceis not the same aspytomography.device, then one must also specify the samedevicein any reconstruction algorithm used. Defaults topytomography.device.FOV_scale_enabled (bool) –
- _get_object_initial(device=pytomography.device)[source]#
Returns an initial object estimate used in reconstruction algorithms. By default, this is a tensor of ones with the same shape as the object metadata.
- Returns:
Initial object used in image reconstruction algorithms.
- Return type:
torch.Tensor
- _get_prior_FOV_scale()[source]#
Sets scaling for the prior within the FOV.
- Returns:
Prior scaling
- Return type:
torch.Tensor
- _compute_attenuation_probability_projection(idx)[source]#
Computes probabilities of photons being detected along an LORs corresponding to
idx.- Parameters:
idx (torch.tensor) – Indices of the detector pairs.
- Returns:
The probabilities of photons being detected along the detector pairs.
- Return type:
torch.Tensor
- _compute_sensitivity_projection(all_ids=True)[source]#
Computes the sensitivty projection (when back projected, gives normalization factor)
- Parameters:
all_ids (bool, optional) – Compute for all detector IDs. Defaults to True.
- Returns:
Sesitivity factor for detector IDs
- Return type:
torch.Tensor
- _backward_full(N_splits=20)[source]#
Computes full back projection \(\tilde{H}^T w g\) where \(w\) is the weighting specified in the projection metadata that accounts for attenuation/normalization correction. If
proj($g$) is not provided, then uses a tensor of all ones (this is used to compute the normalization factor).- Parameters:
N_splits (int, optional) – Optionally splits up computation to save memory on GPU. Defaults to 10.
- set_n_subsets(n_subsets)[source]#
Returns a list where each element consists of an array of indices corresponding to a partitioned version of the projections.
- Parameters:
n_subsets (int) – Number of subsets to partition the projections into
- Returns:
List of arrays where each array corresponds to the projection indices of a particular subset.
- Return type:
list
- get_projection_subset(projections, subset_idx)[source]#
Obtains subsampled projections \(g_m\) corresponding to subset index \(m\). For LM PET, its always the case that \(g_m=1\), but this function is still required for subsampling scatter \(s_m\) as is required in certain reconstruction algorithms
- Parameters:
projections (torch.Tensor) – total projections \(g\)
subset_idx (int) – subset index \(m\)
- Returns:
subsampled projections \(g_m\).
- Return type:
torch.Tensor
- get_weighting_subset(subset_idx)[source]#
Computes the relative weighting of a given subset (given that the projection space is reduced). This is used for scaling parameters relative to \(\tilde{H}_m^T 1\) in reconstruction algorithms, such as prior weighting \(\beta\)
- Parameters:
subset_idx (int) – Subset index
- Returns:
Weighting for the subset.
- Return type:
float
- compute_normalization_factor(subset_idx=None)[source]#
Function called by reconstruction algorithms to get the sensitivty image \(\tilde{H}_m^T w\).
- Parameters:
subset_idx (int | None, optional) – Subset index \(m\). If none, then considers backprojection over all subsets. Defaults to None.
- Returns:
Normalization factor.
- Return type:
torch.tensor
- forward(object, subset_idx=None)[source]#
Computes forward projection. In the case of list mode PET, this corresponds to the expected number of detected counts along each LOR corresponding to a particular object.
- Parameters:
object (torch.tensor) – Object to be forward projected
subset_idx (int, optional) – Subset index \(m\) of the projection. If None, then assumes projection to the entire projection space. Defaults to None.
- Returns:
Projections corresponding to the expected number of counts along each LOR.
- Return type:
torch.tensor
- backward(proj, subset_idx=None, return_norm_constant=False)[source]#
Computes back projection. This corresponds to tracing a sequence of LORs into object space.
- Parameters:
proj (torch.tensor) – Projections to be back projected
subset_idx (int, optional) – Subset index \(m\) of the projection. If None, then assumes projection to the entire projection space. Defaults to None.
return_norm_constant (bool, optional) – Whether or not to return the normalization constant: useful in reconstruction algorithms that require \(H_m^T 1\). Defaults to False.
- Returns:
_description_
- Return type:
torch.tensor
- class pytomography.projectors.PET.PETSinogramSystemMatrix(object_meta, proj_meta, obj2obj_transforms=[], attenuation_map=None, sinogram_sensitivity=None, scale_projection_by_sensitivity=False, N_splits=1, device=pytomography.device)[source]#
Bases:
pytomography.projectors.SystemMatrixSystem matrix for sinogram-based PET reconstruction.
- Parameters:
object_meta (ObjectMeta) – Metadata of object space, containing information on voxel size and dimensions.
proj_meta (PETSinogramPolygonProjMeta) – PET sinogram projection space metadata. This information contains the scanner lookup table and time-of-flight metadata.
obj2obj_transforms (list[Transform], optional) – Object to object space transforms applied before forward projection and after back projection. These are typically used for PSF modeling in PET imaging. Defaults to [].
attenuation_map (torch.tensor | None, optional) – Attenuation map used for attenuation modeling. If provided, all weights will be scaled by detection probabilities derived from this map. Note that this scales on top of
sinogram_sensitivity, so if attenuation is already accounted for there, this is not needed. Defaults to None.sinogram_sensitivity (torch.tensor | None, optional) – Normalization sinogram used to scale projections after forward projection. This factor may include detector normalization \(\eta\) and/or attenuation modeling \(\mu\). The attenuation modeling \(\mu\) should not be included if
attenuation_mapis provided as an argument to the function. Defaults to None.scale_projection_by_sensitivity (bool, optional) – Whether or not to scale the projections by \(\mu \eta\). This is not needed in reconstruction algorithms using a PoissonLogLikelihood. Defaults to False.
N_splits (int, optional) – Splits up computation of forward/back projection to save GPU memory. Defaults to 1.
device (str, optional) – The device for any objects in projection space projection space (what it outputs in forward projection and what it expects for back projection). This is seperate from
pytomography.devicesince the internal functionality may still use GPU even if this is CPU. This is used to save GPU memory since sinograms are often very large. Defaults to pytomography.device.
- _get_xyz_sinogram_coordinates(subset_idx=None)[source]#
Get the XYZ coordinates corresponding to the pair of crystals of the projection angle
- Parameters:
subset_idx (int, optional) – Subset index for ths sinogram. If None, considers all elements. Defaults to None.
- Returns:
XYZ coordinates of crystal 1 and XYZ coordinates of crystal 2 corresponding to all elements in the sinogram.
- Return type:
Sequence[torch.Tensor, torch.Tensor]
- _compute_atteunation_probability_projection(subset_idx)[source]#
Compute the probability of a photon not being attenuated for a certain sinogram element.
- Parameters:
subset_idx (torch.tensor) – Subset index for ths sinogram.
- Returns:
Probability sinogram
- Return type:
torch.tensor
- _compute_sensitivity_sinogram(subset_idx=None)[source]#
Computes the sensitivity sinogram \(\mu \eta\) that accounts for attenuation effects and normalization effects.
- Parameters:
subset_idx (int, optional) – Subset index for ths sinogram. If None, considers all elements. Defaults to None..
- Returns:
Sensitivity sinogram.
- Return type:
torch.Tensor
- set_n_subsets(n_subsets)[source]#
Returns a list where each element consists of an array of indices corresponding to a partitioned version of the projections.
- Parameters:
n_subsets (int) – Number of subsets to partition the projections into
- Returns:
List of arrays where each array corresponds to the projection indices of a particular subset.
- Return type:
list
- get_projection_subset(projections, subset_idx)[source]#
Obtains subsampled projections \(g_m\) corresponding to subset index \(m\). Sinogram PET partitions projections based on angle.
- Parameters:
projections (torch.Tensor) – total projections \(g\)
subset_idx (int) – subset index \(m\)
- Returns:
subsampled projections \(g_m\).
- Return type:
torch.Tensor
- get_weighting_subset(subset_idx)[source]#
Computes the relative weighting of a given subset (given that the projection space is reduced). This is used for scaling parameters relative to \(\tilde{H}_m^T 1\) in reconstruction algorithms, such as prior weighting \(\beta\)
- Parameters:
subset_idx (int) – Subset index
- Returns:
Weighting for the subset.
- Return type:
float
- compute_normalization_factor(subset_idx=None)[source]#
Computes the normalization factor \(H^T \mu \eta\)
- Parameters:
subset_idx (int, optional) – Subset index for ths sinogram. If None, considers all elements. Defaults to None..
- Returns:
Normalization factor.
- Return type:
torch.Tensor
- forward(object, subset_idx=None)[source]#
PET Sinogram forward projection
- Parameters:
object (torch.tensor) – Object to be forward projected
subset_idx (int, optional) – Subset index for ths sinogram. If None, considers all elements. Defaults to None.
scale_by_sensitivity (bool, optional) – Whether or not to scale the projections by \(\mu \eta\). This is not necessarily needed in reconstruction algorithms. Defaults to False.
- Returns:
Forward projection
- Return type:
torch.tensor
- backward(proj, subset_idx=None, force_scale_by_sensitivity=False, force_nonTOF=False)[source]#
PET Sinogram back projection
- Parameters:
proj (torch.tensor) – Sinogram to be back projected
subset_idx (int, optional) – Subset index for ths sinogram. If None, considers all elements. Defaults to None.
scale_by_sensitivity (bool, optional) – Whether or not to scale the projections by \(\mu \eta\). This is not necessarily needed in reconstruction algorithms. Defaults to False.
force_nonTOF (bool, optional) – Force non-TOF projection, even if TOF metadata is contained in the projection metadata. This is used for computing normalization factors (which don’t depend on TOF). Defaults to False.
- Returns:
Back projection.
- Return type:
torch.tensor
- pytomography.projectors.PET.create_sinogramSM_from_LMSM(lm_system_matrix, device='cpu')[source]#
Generates a sinogram system matrix from a listmode system matrix. This is used in the single scatter simulation algorithm.
- Parameters:
lm_system_matrix (SystemMatrix) – A listmode PET system matrix
device (str, optional) – The device for any objects in projection space projection space (what it outputs in forward projection and what it expects for back projection). This is seperate from
pytomography.devicesince the internal functionality may still use GPU even if this is CPU. This is used to save GPU memory since sinograms are often very large. Defaults to pytomography.device.
- Returns:
PET sinogram system matrix generated via a corresponding PET listmode system matrix.
- Return type: