pytomography.io.SPECT#

Input/output functions for the SPECT imaging modality. Currently, the data types supported are SIMIND and DICOM files.

Submodules#

Package Contents#

Functions#

get_attenuation_map(headerfile)

Opens attenuation data from SIMIND output

get_projections(file[, index_peak, index_time, ...])

Gets 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.

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_psfmeta_from_scanner_params(collimator_name, ...)

Obtains SPECT PSF metadata given a unique collimator code and photopeak energy of radionuclide. For more information on collimator codes, see the "external data" section of the readthedocs page.

open_CT_file(files_CT)

Given a list of seperate DICOM files, opens them up and stacks them together into a single CT image.

CT_to_mumap(CT, files_CT, file_NM[, index_peak])

Converts a CT image to a mu-map given SPECT projection data. The CT data must be aligned with the projection data already; this is a helper function for get_attenuation_map_from_CT_slices.

pytomography.io.SPECT.get_attenuation_map(headerfile)[source]#

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_projections(file, index_peak=None, index_time=None, print_shape=True)[source]#

Gets projections from a .dcm file.

Parameters:
  • file (str) – Path to the .dcm file of SPECT projection data.

  • 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.

  • index_time (int) – If not none, then the returned projections correspond to the index of the time slot in gated SPECT. Otherwise returns all time slots. Defaults to None

  • print_shape (bool) – If true, then prints the shape of the projections returned. Defaults to true.

Returns:

(SPECTObjectMeta, SPECTProjMeta, torch.Tensor[…, Ltheta, Lr, Lz]) where … depends on if time slots are considered.

Return type:

Sequence[pytomography.metadata.SPECTObjectMeta, pytomography.metadata.SPECTProjMeta, torch.Tensor]

pytomography.io.SPECT.get_attenuation_map_from_file(file_AM)[source]#

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')[source]#

Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography.

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)[source]#

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_psfmeta_from_scanner_params(collimator_name, energy_keV, min_sigmas=3)[source]#

Obtains SPECT PSF metadata given a unique collimator code and photopeak energy of radionuclide. For more information on collimator codes, see the “external data” section of the readthedocs page.

Parameters:
  • collimator_name (str) – Code for the 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:

SPECTPSFMeta

pytomography.io.SPECT.open_CT_file(files_CT)#

Given a list of seperate DICOM files, opens them up and stacks them together into a single CT image.

Parameters:

files_CT (Sequence[str]) – List of CT DICOM filepaths corresponding to different z slices of the same scan.

Returns:

CT scan in units of Hounsfield Units at the effective CT energy.

Return type:

np.array

pytomography.io.SPECT.CT_to_mumap(CT, files_CT, file_NM, index_peak=0)[source]#

Converts a CT image to a mu-map given SPECT projection data. The CT data must be aligned with the projection data already; this is a helper function for get_attenuation_map_from_CT_slices.

Parameters:
  • CT (torch.tensor) – CT object in units of HU

  • files_CT (Sequence[str]) – Filepaths of all CT slices

  • file_NM (str) – Filepath of SPECT projectio ndata

  • index_peak (int, optional) – Index of EnergyInformationSequence corresponding to the photopeak. Defaults to 0.

Returns:

Attenuation map in units of 1/cm

Return type:

torch.tensor