pytomography.io.io_utils — PyTomography 0.8.0 documentation

Skip to main content
`Ctrl`+`K`

# `pytomography.io.io_utils`

This module contains helper function for inputting/outputting/interpretting SPECT/CT data in the SIMIND and DICOM file formats. A considerable amount of these functions have to do with creating attenuation maps from CT data files for attenuation correction in SPECT imaging.

## Module Contents

### Functions

`compute_TEW`(projection_lower, projection_upper, ...) |
`dual_sqrt_exponential`(energy, c1, c2, d1, d2) | Function used for curve fitting of linear attenuation coefficient vs. photon energy curves from NIST. It's given by the functional form \(f(x) = c_1e^{-d_1\sqrt{x}} + c_2e^{-d_2\sqrt{x}}\). It was chosen purely because it gave good fit results.
`bilinear_transform`(HU, a1, a2, b1, b2) | Function used to convert between Hounsfield Units at an effective CT energy and linear attenuation coefficient at a given SPECT radionuclide energy. It consists of two distinct linear curves in regions \(HU<0\) and \(HU \geq 0\).
`open_CT_file`(files_CT[, return_max_slice_loc]) | Given a list of seperate DICOM files, opens them up and stacks them together into a single CT image.
`get_E_mu_data_from_datasheet`(file) | Return energy and linear attenuation data from NIST datafiles of mass attenuation coefficients between 50keV and 511keV.
`get_mu_from_spectrum_interp`(file, energy) | Gets linear attenuation corresponding to a given energy in in the data from `file`.
`get_HU_from_spectrum_interp`(file, energy) | Obtains the Hounsfield Units of some material at a given energy
`get_HU_mu_curve`(files_CT, CT_kvp, E_SPECT) | Gets Housnfield Unit vs. linear attenuation coefficient for air, water, and cortical bone data points
`HU_to_mu`(HU, E, p_water_opt, p_air_opt) | Converts hounsfield units to linear attenuation coefficient
`get_HU_corticalbone`(files_CT) | Obtains the Hounsfield Unit corresponding to cortical bone from a CT scan.
`get_ECT_from_corticalbone_HU`(HU) | Finds the effective CT energy that gives a cortical bone Hounsfield Unit value corresponding to `HU`.
`get_HU2mu_conversion`(files_CT, CT_kvp, E_SPECT) | Obtains the HU to mu conversion function that converts CT data to the required linear attenuation value in units of 1/cm required for attenuation correction in SPECT/PET imaging.

### Attributes

`module_path` |
`DATADIR` |
`FILE_WATER` |
`FILE_AIR` |
`FILE_CBONE` |

pytomography.io.io_utils.module_path

pytomography.io.io_utils.DATADIR

pytomography.io.io_utils.FILE_WATER

pytomography.io.io_utils.FILE_AIR

pytomography.io.io_utils.FILE_CBONE

pytomography.io.io_utils.compute_TEW(projection_lower, projection_upper, width_lower, width_upper, width_peak)

pytomography.io.io_utils.dual_sqrt_exponential(energy, c1, c2, d1, d2)

  Function used for curve fitting of linear attenuation coefficient vs. photon energy curves from NIST. It’s given by the functional form \(f(x) = c_1e^{-d_1\sqrt{x}} + c_2e^{-d_2\sqrt{x}}\). It was chosen purely because it gave good fit results.

  Parameters:

    - energy (float) – Energy of photon

    - c1 (float) – Fit parameter 1

    - c2 (float) – Fit parameter 2

    - d1 (float) – Fit parameter 3

    - d2 (float) – Fit parameter 4

  Returns:

    _description_

  Return type:

    float

pytomography.io.io_utils.bilinear_transform(HU, a1, a2, b1, b2)

  Function used to convert between Hounsfield Units at an effective CT energy and linear attenuation coefficient at a given SPECT radionuclide energy. It consists of two distinct linear curves in regions \(HU<0\) and \(HU \geq 0\).

  Parameters:

    - HU (float) – Hounsfield units at CT energy

    - a1 (float) – Fit parameter 1

    - a2 (float) – Fit parameter 2

    - b1 (float) – Fit parameter 3

    - b2 (float) – Fit parameter 4

  Returns:

    Linear attenuation coefficient at SPECT energy

  Return type:

    float

pytomography.io.io_utils.open_CT_file(files_CT, return_max_slice_loc=False)

  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 DICOM files corresponding to a particular scan

    - return_max_slice_loc (bool, optional) – Whether or not to return the max slice location of all the CT files. Needed when applying affine transformation to align CT and SPECT images. Defaults to False.

  Returns:

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

  Return type:

    np.array

pytomography.io.io_utils.get_E_mu_data_from_datasheet(file)

  Return energy and linear attenuation data from NIST datafiles of mass attenuation coefficients between 50keV and 511keV.

  Parameters:

    file (str) – Location of NIST data file. Corresponds to a particular element/material.

  Returns:

    Energy and linear attenuation values.

  Return type:

    tuple[np.array, np.array]

pytomography.io.io_utils.get_mu_from_spectrum_interp(file, energy)

  Gets linear attenuation corresponding to a given energy in in the data from `file`.

  Parameters:

    - file (str) – Filepath of the mu-energy data

    - energy (float) – Energy at which mu is computed

  Returns:

    Linear attenuation coefficient (in 1/cm) at the desired energies.

  Return type:

    np.array

pytomography.io.io_utils.get_HU_from_spectrum_interp(file, energy)

  Obtains the Hounsfield Units of some material at a given energy

  Parameters:

    - file (str) – Filepath of material

    - energy (float) – Energy at which HU is desired

  Returns:

    HU at the desired energies.

  Return type:

    np.array

pytomography.io.io_utils.get_HU_mu_curve(files_CT, CT_kvp, E_SPECT)

  Gets Housnfield Unit vs. linear attenuation coefficient for air, water, and cortical bone data points

  Parameters:

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

    - CT_kvp (float) – Value of kVp for the CT scan

    - E_SPECT (float) – Photopeak energy of the SPECT scan

  Return type:

    tuple[np.array, np.array]

pytomography.io.io_utils.HU_to_mu(HU, E, p_water_opt, p_air_opt)

  Converts hounsfield units to linear attenuation coefficient

  Parameters:

    - HU (float) – Hounsfield Unit value

    - E (float) – Effective CT energy

    - p_water_opt (Sequence[float]) – Optimal fit parameters for mu vs. E data for water

    - p_air_opt (Sequence[float]) – Optimal fit parameters for mu vs. E data for air

  Returns:

    _description_

  Return type:

    _type_

pytomography.io.io_utils.get_HU_corticalbone(files_CT)

  Obtains the Hounsfield Unit corresponding to cortical bone from a CT scan.

  Parameters:

    files_CT (Sequence[str]) – CT data files

  Returns:

    Hounsfield unit of bone. If not found, then returns `None`.

  Return type:

    float | None

pytomography.io.io_utils.get_ECT_from_corticalbone_HU(HU)

  Finds the effective CT energy that gives a cortical bone Hounsfield Unit value corresponding to `HU`.

  Parameters:

    HU (float) – Hounsfield Unit of Cortical bone at effective CT energy

  Returns:

    Effective CT energy

  Return type:

    float

pytomography.io.io_utils.get_HU2mu_conversion(files_CT, CT_kvp, E_SPECT)

  Obtains the HU to mu conversion function that converts CT data to the required linear attenuation value in units of 1/cm required for attenuation correction in SPECT/PET imaging.

  Parameters:

    - files_CT (Sequence[str]) – CT data files

    - CT_kvp (float) – kVp value for CT scan

    - E_SPECT (float) – Energy of photopeak in SPECT scan

  Returns:

    Conversion function from HU to mu.

  Return type:

    function