pytomography.io.SPECT.dicom — PyTomography 0.8.0 documentation

Skip to main content
`Ctrl`+`K`

# `pytomography.io.SPECT.dicom`

## Module Contents

### Functions

`get_radii_and_angles`(ds) | Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file.
`get_projections`(file[, index_peak]) | Gets ObjectMeta, ImageMeta, and projections from a .dcm file.
`get_window_width`(ds, index) | Computes the width of an energy window corresponding to a particular index in the DetectorInformationSequence DICOM attribute.
`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_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_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.
`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_affine_spect`(ds) | Computes an affine matrix corresponding the coordinate system of a SPECT DICOM file.
`get_affine_CT`(ds, max_z) | Computes an affine matrix corresponding the coordinate system of a CT DICOM file. Note that since CT scans consist of many independent DICOM files, ds corresponds to an individual one of these files. This is why the maximum z value is also required (across all seperate independent DICOM files).
`stitch_multibed`(recons, files_NM[, method]) | Stitches together multiple reconstructed objects corresponding to different bed positions.

pytomography.io.SPECT.dicom.get_radii_and_angles(ds)

  Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file.

  Parameters:

    ds (Dataset) – pydicom dataset object.

  Returns:

    Required image data for reconstruction.

  Return type:

    (torch.tensor[1,Ltheta, Lr, Lz], np.array, np.array)

pytomography.io.SPECT.dicom.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.dicom.get_window_width(ds, index)

  Computes the width of an energy window corresponding to a particular index in the DetectorInformationSequence DICOM attribute.

  Parameters:

    - ds (Dataset) – DICOM dataset.

    - index (int) – Energy window index corresponding to the DICOM dataset.

  Returns:

    Range of the energy window in keV

  Return type:

    float

pytomography.io.SPECT.dicom.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.dicom.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.dicom.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

pytomography.io.SPECT.dicom.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.dicom.get_affine_spect(ds)

  Computes an affine matrix corresponding the coordinate system of a SPECT DICOM file.

  Parameters:

    ds (Dataset) – DICOM dataset of projection data

  Returns:

    Affine matrix.

  Return type:

    np.array

pytomography.io.SPECT.dicom.get_affine_CT(ds, max_z)

  Computes an affine matrix corresponding the coordinate system of a CT DICOM file. Note that since CT scans consist of many independent DICOM files, ds corresponds to an individual one of these files. This is why the maximum z value is also required (across all seperate independent DICOM files).

  Parameters:

    - ds (Dataset) – DICOM dataset of CT data

    - max_z (float) – Maximum value of z across all axial slices that make up the CT scan

  Returns:

    Affine matrix corresponding to CT scan.

  Return type:

    np.array

pytomography.io.SPECT.dicom.stitch_multibed(recons, files_NM, method='midslice')

  Stitches together multiple reconstructed objects corresponding to different bed positions.

  Parameters:

    - recons (torch.Tensor[n_beds, Lx, Ly, Lz]) – Reconstructed objects. The first index of the tensor corresponds to different bed positions

    - files_NM (list) – List of length `n_beds` corresponding to the DICOM file of each reconstruction

    - method (str, optional) – Method to perform stitching (see https://doi.org/10.1117/12.2254096 for all methods described). Available methods include `'midslice'`, `'average'`, `'crossfade'`, and `'TEM;` (transition error minimization).

  Returns:

    Stitched together DICOM file. Note the new z-dimension size \(L_z'\).

  Return type:

    torch.Tensor[1, Lx, Ly, Lz’]