pytomography.io.dicom - PyTomography 0.4.1 documentation

Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# `pytomography.io.dicom`

Note: This module is still being built and is not yet finished.

## Module Contents

### Functions

`get_radii_and_angles`(ds) | Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file.
`dicom_projections_to_data`(file) | Obtains ObjectMeta, ImageMeta, and projections from a .dcm file.
`dicom_MEW_to_data`(file[, type]) |
`get_HU2mu_coefficients`(ds[, photopeak_window_index]) | Obtains the four coefficients required for the bilinear transformation between Hounsfield Units and linear attenuation coefficient at the photon energy corresponding to the primary window of the given dataset.
`bilinear_transform`(arr, a1, b1, a2, b2) | Converts an array of Hounsfield Units into linear attenuation coefficient using the bilinear transformation \(f(x)=a_1x+b_1\) for positive \(x\) and \(f(x)=a_2x+b_2\) for negative \(x\).
`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).
`dicom_CT_to_data`(files_CT, file_NM[, ...]) | Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography. This is primarily intended for opening pre-reconstructed CT data such that it can be used as an attenuation map during PET/SPECT reconstruction.
`get_SPECT_recon_algorithm_dicom`(projections_file[, ...]) | Helper function to quickly create reconstruction algorithm given SPECT DICOM files and CT dicom files.

pytomography.io.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.dicom.dicom_projections_to_data(file)

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

  Parameters:

    file (str) – Path to the .dcm file

  Returns:

    Required information for reconstruction in PyTomography.

  Return type:

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

pytomography.io.dicom.dicom_MEW_to_data(file, type='DEW')

pytomography.io.dicom.get_HU2mu_coefficients(ds, photopeak_window_index=0)

  Obtains the four coefficients required for the bilinear transformation between Hounsfield Units and linear attenuation coefficient at the photon energy corresponding to the primary window of the given dataset.

  Parameters:

    - ds (Dataset) – DICOM data set of projection data

    - primary_window_index (int, optional) – The energy window corresponding to the photopeak. Defaults to 0.

    - photopeak_window_index (int) –

  Returns:

    Array of length 4 containins the 4 coefficients required for the bilinear transformation.

  Return type:

    np.array

pytomography.io.dicom.bilinear_transform(arr, a1, b1, a2, b2)

  Converts an array of Hounsfield Units into linear attenuation coefficient using the bilinear transformation \(f(x)=a_1x+b_1\) for positive \(x\) and \(f(x)=a_2x+b_2\) for negative \(x\).

  Parameters:

    - arr (np.array) – Array to be transformed using bilinear transformation

    - a1 (float) – Bilinear slope for negative input values

    - b1 (float) – Bilinear intercept for negative input values

    - a2 (float) – Bilinear slope for positive input values

    - b2 (float) – Bilinear intercept for positive input values

  Returns:

    Transformed array.

  Return type:

    np.array

pytomography.io.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.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.dicom.dicom_CT_to_data(files_CT, file_NM, photopeak_window_index=0)

  Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography. This is primarily intended for opening pre-reconstructed CT data such that it can be used as an attenuation map during PET/SPECT reconstruction.

  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)

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

  Returns:

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

  Return type:

    torch.Tensor

pytomography.io.dicom.get_SPECT_recon_algorithm_dicom(projections_file, atteunation_files=None, use_psf=False, scatter_type=None, prior=None, recon_algorithm_class=OSEMOSL, object_initial=None)

  Helper function to quickly create reconstruction algorithm given SPECT DICOM files and CT dicom files.

  Parameters:

    - projections_file (str) – DICOM filepath corresponding to SPECT data.

    - atteunation_files (Sequence[str], optional) – DICOM filepaths corresponding to CT data. If None, then atteunation correction is not used. Defaults to None.

    - use_psf (bool, optional) – Whether or not to use PSF modeling. Defaults to False.

    - scatter_type (str | None, optional) – Type of scatter correction used in reconstruction. Defaults to None.

    - prior (Prior, optional) – Bayesian Prior used in reconstruction algorithm. Defaults to None.

    - recon_algorithm_class (nn.Module, optional) – Type of reconstruction algorithm used. Defaults to OSEMOSL.

    - object_initial (torch.Tensor | None, optional) – Initial object used in reconstruction. If None, defaults to all ones. Defaults to None.

  Raises:

    Exception – If not able to compute relevant PSF parameters from DICOM data and corresponding data tables.

  Returns:

    Reconstruction algorithm used.

  Return type:

    OSML