pytomography.io.SPECT — PyTomography 0.8.0 documentation

Skip to main content
`Ctrl`+`K`

# `pytomography.io.SPECT`

## Submodules

- `pytomography.io.SPECT.dicom`
- `pytomography.io.SPECT.simind`

## Package Contents

### Functions

`get_atteuation_map`(headerfile) | Opens attenuation data from SIMIND output
`get_SPECT_recon_algorithm_simind`(projections_header[, ...]) |
`get_projections`(file[, index_peak]) | Gets ObjectMeta, ImageMeta, and projections from a .dcm file.
`get_attenuation_map_from_file`(file_AM) | Gets an attenuation map from a DICOM file. This data is usually provided by the manufacturer of the SPECT scanner.
`get_attenuation_map_from_CT_slices`(files_CT[, ...]) | Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography. Note that it is recommended by https://jnm.snmjournals.org/content/57/1/151.long to use the vendors attenuation map as opposed to creating your own. As such, the `get_attenuation_map_from_file` should be used preferentially over this function, if you have access to an attenuation map from the vendor.
`get_scatter_from_TEW`(file, index_peak, index_lower, ...) | Gets an estimate of scatter projection data from a DICOM file using the triple energy window method.
`get_blank_below_above`(image) | Obtains the number of blank z-slices at the sup (`blank_above`) and inf (`blank_below`) of the projection data. This method is entirely empircal, and looks for z slices where there are zero detected counts.
`get_psfmeta_from_scanner_params`(camera_model, ...[, ...]) | Gets PSF metadata from SPECT camera/collimator parameters. Performs linear interpolation to find linear attenuation coefficient for lead collimators for energy values within the range 100keV - 600keV.

pytomography.io.SPECT.get_atteuation_map(headerfile)

  Opens attenuation data from SIMIND output

  Parameters:

    headerfile (str) – Path to header file

  Returns:

    Tensor containing attenuation map required for attenuation correction in SPECT/PET imaging.

  Return type:

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

pytomography.io.SPECT.get_SPECT_recon_algorithm_simind(projections_header, scatter_headers=None, CT_header=None, psf_meta=None, prior=None, object_initial=None, recon_algorithm_class=OSEMOSL)
  Parameters:

    - projections_header (str) –

    - scatter_headers (Sequence[str] | None) –

    - CT_header (str) –

    - psf_meta (pytomography.metadata.PSFMeta) –

    - prior (pytomography.priors.Prior) –

    - object_initial (torch.Tensor | None) –

    - recon_algorithm_class (torch.nn.Module) –

  Return type:

    torch.nn.Module

pytomography.io.SPECT.get_projections(file, index_peak=None)

  Gets ObjectMeta, ImageMeta, and projections from a .dcm file.

  Parameters:

    - file (str) – Path to the .dcm file

    - index_peak (int) – If not none, then the returned projections correspond to the index of this energy window. Otherwise returns all energy windows. Defaults to None.

  Returns:

    Required information for reconstruction in PyTomography.

  Return type:

    (ObjectMeta, ImageMeta, torch.Tensor[1, Ltheta, Lr, Lz])

pytomography.io.SPECT.get_attenuation_map_from_file(file_AM)

  Gets an attenuation map from a DICOM file. This data is usually provided by the manufacturer of the SPECT scanner.

  Parameters:

    file_AM (str) – File name of attenuation map

  Returns:

    Tensor of shape [batch_size, Lx, Ly, Lz] corresponding to the atteunation map in units of cm:math:^{-1}

  Return type:

    torch.Tensor

pytomography.io.SPECT.get_attenuation_map_from_CT_slices(files_CT, file_NM=None, index_peak=0, keep_as_HU=False, mode='nearest')

  Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography. Note that it is recommended by https://jnm.snmjournals.org/content/57/1/151.long to use the vendors attenuation map as opposed to creating your own. As such, the `get_attenuation_map_from_file` should be used preferentially over this function, if you have access to an attenuation map from the vendor.

  Parameters:

    - files_CT (Sequence[str]) – List of all files corresponding to an individual CT scan

    - file_NM (str) – File corresponding to raw PET/SPECT data (required to align CT with projections). If None, then no alignment is done. Defaults to None.

    - index_peak (int, optional) – Index corresponding to photopeak in projection data. Defaults to 0.

    - keep_as_HU (bool) – If True, then don’t convert to linear attenuation coefficient and keep as Hounsfield units. Defaults to False

    - mode (str) –

  Returns:

    Tensor of shape [Lx, Ly, Lz] corresponding to attenuation map.

  Return type:

    torch.Tensor

pytomography.io.SPECT.get_scatter_from_TEW(file, index_peak, index_lower, index_upper)

  Gets an estimate of scatter projection data from a DICOM file using the triple energy window method.

  Parameters:

    - file (str) – Filepath of the DICOM file

    - index_peak (int) – Index of the `EnergyWindowInformationSequence` DICOM attribute corresponding to the photopeak.

    - index_lower (int) – Index of the `EnergyWindowInformationSequence` DICOM attribute corresponding to lower scatter window.

    - index_upper (int) – Index of the `EnergyWindowInformationSequence` DICOM attribute corresponding to upper scatter window.

  Returns:

    Tensor corresponding to the scatter estimate.

  Return type:

    torch.Tensor[1,Ltheta,Lr,Lz]

pytomography.io.SPECT.get_blank_below_above(image)

  Obtains the number of blank z-slices at the sup (`blank_above`) and inf (`blank_below`) of the projection data. This method is entirely empircal, and looks for z slices where there are zero detected counts.

  Parameters:

    image (torch.tensor) – Image data from a scanner

  Returns:

    A tuple of two elements corresponding to the number of blank slices at the inf, and the number of blank slices at the sup.

  Return type:

    Sequence[int]

pytomography.io.SPECT.get_psfmeta_from_scanner_params(camera_model, collimator_name, energy_keV, min_sigmas=3)

  Gets PSF metadata from SPECT camera/collimator parameters. Performs linear interpolation to find linear attenuation coefficient for lead collimators for energy values within the range 100keV - 600keV.

  Parameters:

    - camera_model (str) – Name of SPECT camera.

    - collimator_name (str) – Name of collimator used.

    - energy_keV (float) – Energy of the photopeak

    - min_sigmas (float) – Minimum size of the blurring kernel used. Fixes the convolutional kernel size so that all locations have at least `min_sigmas` in dimensions (some will be greater)

  Returns:

    PSF metadata.

  Return type:

    PSFMeta