pytomography.transforms.SPECT#
Submodules#
Package Contents#
Classes#
obj2obj transform used to model the effects of attenuation in SPECT. This transform accepts either an |
|
obj2obj transform used to model the effects of PSF blurring in SPECT. The smoothing kernel used to apply PSF modeling uses a Gaussian kernel with width \(\sigma\) dependent on the distance of the point to the detector; that information is specified in the |
|
The parent class for all transforms used in reconstruction (obj2obj, im2im, obj2im). Subclasses must implement the |
|
The parent class for all transforms used in reconstruction (obj2obj, im2im, obj2im). Subclasses must implement the |
- class pytomography.transforms.SPECT.SPECTAttenuationTransform(attenuation_map=None, filepath=None, mode='constant', assume_padded=True, HU2mu_technique='from_table')[source]#
Bases:
pytomography.transforms.Transformobj2obj transform used to model the effects of attenuation in SPECT. This transform accepts either an
attenuation_map(which must be aligned with the SPECT projection data) or afilepathconsisting of folder containing CT DICOM files all pertaining to the same scan- Parameters:
attenuation_map (torch.tensor) – Tensor of size [Lx, Ly, Lz] corresponding to the attenuation coefficient in \({\text{cm}^{-1}}\) at the photon energy corresponding to the particular scan
filepath (Sequence[str]) – Folder location of CT scan; all .dcm files must correspond to different slices of the same scan.
mode (str) – Mode used for extrapolation of CT beyond edges when aligning DICOM SPECT/CT data. Defaults to ‘constant’, which means the image is padded with zeros.
assume_padded (bool) – Assumes objects and projections fed into forward and backward methods are padded, as they will be in reconstruction algorithms
HU2mu_technique (str) – Technique to convert HU to attenuation coefficients. The default, ‘from_table’, uses a table of coefficients for bilinear curves obtained for a variety of common radionuclides. The technique ‘from_cortical_bone_fit’ looks for a cortical bone peak in the scan and uses that to obtain the bilinear coefficients. For phantom scans where the attenuation coefficient is always significantly less than bone, the corticol bone technique will still work, since the first part of the bilinear curve (in the air to water range) does not depend on the cortical bone fit. Alternatively, one can provide an arbitrary function here which takes in a 3D scan with units of HU and converts to mu.
- configure(object_meta, proj_meta)[source]#
Function used to initalize the transform using corresponding object and projection metadata
- Parameters:
object_meta (SPECTObjectMeta) – Object metadata.
proj_meta (SPECTProjMeta) – Projection metadata.
- Return type:
None
- forward(object_i, ang_idx)[source]#
Forward projection \(A:\mathbb{U} \to \mathbb{U}\) of attenuation correction.
- Parameters:
object_i (torch.tensor) – Tensor of size [Lx, Ly, Lz] being projected along
axis=0.ang_idx (torch.Tensor) – The projection indices: used to find the corresponding angle in projection space corresponding to each projection angle in
object_i.
- Returns:
Tensor of size [Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to an attenuation corrected projection.
- Return type:
torch.tensor
- backward(object_i, ang_idx)[source]#
Back projection \(A^T:\mathbb{U} \to \mathbb{U}\) of attenuation correction. Since the matrix is diagonal, the implementation is the same as forward projection. The only difference is the optional normalization parameter.
- Parameters:
object_i (torch.tensor) – Tensor of size [Lx, Ly, Lz] being projected along
axis=0.ang_idx (torch.Tensor) – The projection indices: used to find the corresponding angle in projection space corresponding to each projection angle in
object_i.norm_constant (torch.tensor, optional) – A tensor used to normalize the output during back projection. Defaults to None.
- Returns:
Tensor of size [Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to an attenuation corrected projection.
- Return type:
torch.tensor
- class pytomography.transforms.SPECT.SPECTPSFTransform(psf_meta=None, psf_operator=None, assume_padded=True)[source]#
Bases:
pytomography.transforms.Transformobj2obj transform used to model the effects of PSF blurring in SPECT. The smoothing kernel used to apply PSF modeling uses a Gaussian kernel with width \(\sigma\) dependent on the distance of the point to the detector; that information is specified in the
SPECTPSFMetaparameter. There are a few potential arguments to initialize this transform (i) psf_meta, which contains relevant collimator information to obtain a Gaussian PSF model that works for low/medium energy SPECT (ii) kernel_f, an callable function that gives the kernel at any source-detector distance \(d\), or (iii) psf_operator, a network configured to automatically apply full PSF modeling to a given object \(f\) at all source-detector distances. Only one of the arguments should be given.- Parameters:
psf_meta (SPECTPSFMeta) – Metadata corresponding to the parameters of PSF blurring. In most cases (low/medium energy SPECT), this should be the only given argument.
kernel_f (Callable) – Function \(PSF(x,y,d)\) that gives PSF at every source-detector distance \(d\). It should be able to take in 1D numpy arrays as its first two arguments, and a single argument for the final argument \(d\). The function should return a corresponding 2D PSF kernel.
psf_operator (Callable) – Network that takes in an object \(f\) and applies all necessary PSF correction to return a new object \(\tilde{f}\) that is PSF corrected, such that subsequent summation along the x-axis accurately models the collimator detector response.
assume_padded (bool) –
- _configure_simple_model()[source]#
Internal function to configure Gaussian modeling. This is called when psf_meta is given in initialization
- _configure_manual_net()[source]#
Internal function to configure the PSF net. This is called when psf_operator is given in initialization
- configure(object_meta, proj_meta)[source]#
Function used to initalize the transform using corresponding object and projection metadata
- Parameters:
object_meta (SPECTObjectMeta) – Object metadata.
proj_meta (SPECTProjMeta) – Projections metadata.
- Return type:
None
- _compute_kernel_size(radius, axis)[source]#
Function used to compute the kernel size used for PSF blurring. In particular, uses the
min_sigmasattribute ofSPECTPSFMetato determine what the kernel size should be such that the kernel encompasses at leastmin_sigmasat all points in the object.- Returns:
The corresponding kernel size used for PSF blurring.
- Return type:
int
- _get_sigma(radius)[source]#
Uses PSF Meta data information to get blurring \(\sigma\) as a function of distance from detector.
- Parameters:
radius (float) – The distance from the detector.
- Returns:
An array of length Lx corresponding to blurring at each point along the 1st axis in object space
- Return type:
array
- forward(object, ang_idx)[source]#
Applies the PSF transform \(A:\mathbb{U} \to \mathbb{U}\) for the situation where an object is being detector by a detector at the \(+x\) axis.
- Parameters:
object_i (torch.tensor) – Tensor of size [Lx, Ly, Lz] being projected along its first axis
ang_idx (int) – The projection indices: used to find the corresponding angle in projection space corresponding to each projection angle in
object_i.object (torch.Tensor) –
- Returns:
Tensor of size [Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to n PSF corrected projection.
- Return type:
torch.tensor
- backward(object, ang_idx)[source]#
Applies the transpose of the PSF transform \(A^T:\mathbb{U} \to \mathbb{U}\) for the situation where an object is being detector by a detector at the \(+x\) axis. Since the PSF transform is a symmetric matrix, its implemtation is the same as the
forwardmethod.- Parameters:
object_i (torch.tensor) – Tensor of size [Lx, Ly, Lz] being projected along its first axis
ang_idx (int) – The projection index
object (torch.Tensor) –
- Returns:
Tensor of size [Lx, Ly, Lz] such that projection of this tensor along the first axis corresponds to n PSF corrected projection.
- Return type:
torch.tensor
- class pytomography.transforms.SPECT.CutOffTransform(mask)[source]#
Bases:
pytomography.transforms.TransformThe parent class for all transforms used in reconstruction (obj2obj, im2im, obj2im). Subclasses must implement the
__call__method.- Parameters:
device (str) – Pytorch device used for computation
- forward(proj, padded=True)[source]#
Cuts off the projection data outside of a certain region. :param proj: Projection data :type proj: torch.Tensor :param padded: Whether or not the projection data is padded. Defaults to True. :type padded: bool, optional
- Returns:
Projection data with cutoff applied
- Return type:
torch.Tensor
- Parameters:
proj (torch.Tensor) –
padded (bool) –
- backward(proj, padded=True)[source]#
Returns the projection data without the cutoff. :param proj: Projection data :type proj: torch.Tensor :param padded: Whether or not the projection data is padded. Defaults to True. :type padded: bool, optional
- Returns:
Projection data without cutoff
- Return type:
torch.Tensor
- Parameters:
proj (torch.Tensor) –
padded (bool) –
- class pytomography.transforms.SPECT.AdditiveTermTransform(additive_term)[source]#
Bases:
pytomography.transforms.TransformThe parent class for all transforms used in reconstruction (obj2obj, im2im, obj2im). Subclasses must implement the
__call__method.- Parameters:
device (str) – Pytorch device used for computation
additive_term (float) –
- forward(proj, padded=True)[source]#
Adds an additive term to the projection data. :param proj: Projection data :type proj: torch.Tensor :param padded: Whether or not the projection data is padded. Defaults to True. :type padded: bool, optional
- Returns:
Projection data with additive term added
- Return type:
torch.Tensor
- Parameters:
proj (torch.Tensor) –
padded (bool) –
- backward(proj, padded=True)[source]#
Returns the projection data without the additive term. :param proj: Projection data :type proj: torch.Tensor :param padded: Whether or not the projection data is padded. Defaults to True. :type padded: bool, optional
- Returns:
Projection data without additive term
- Return type:
torch.Tensor
- Parameters:
proj (torch.Tensor) –
padded (bool) –