pytomography.io.SPECT.dicom
#
Note: This module is still being built and is not yet finished.
Module Contents#
Functions#
Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file. |
|
|
Gets ObjectMeta, ImageMeta, and projections from a .dcm file. |
|
Computes the width of an energy window corresponding to a particular index in the DetectorInformationSequence DICOM attribute. |
|
Gets an estimate of scatter projection data from a DICOM file using the triple energy window method. |
|
Gets an attenuation map from a DICOM file. This data is usually provided by the manufacturer of the SPECT scanner. |
|
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. |
|
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 |
|
Obtains an attenuation map from a CT file. Requires dataset corresponding to projection data because energy windows are used to convert from HU to linear attenuation coefficients. See https://www.sciencedirect.com/science/article/pii/S0969804308000067 for more details. |
|
Computes an affine matrix corresponding the coordinate system of a SPECT DICOM file. |
|
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). |
|
Stitches together multiple reconstructed objects corresponding to different bed positions. |
- pytomography.io.SPECT.dicom.get_radii_and_angles(ds)[source]#
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)[source]#
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)[source]#
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)[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.dicom.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.dicom.get_psfmeta_from_scanner_params(camera_model, collimator_name, energy_keV)[source]#
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
- Returns:
PSF metadata.
- Return type:
- pytomography.io.SPECT.dicom.get_attenuation_map_from_CT_slices(files_CT, file_NM, index_peak=0)[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. 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)
index_peak (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.SPECT.dicom.CT_to_attenuation_map(CT_HU, ds, photopeak_window_index=0)[source]#
Obtains an attenuation map from a CT file. Requires dataset corresponding to projection data because energy windows are used to convert from HU to linear attenuation coefficients. See https://www.sciencedirect.com/science/article/pii/S0969804308000067 for more details.
- Parameters:
CT_HU (np.array) – CT object in units of hounsfield units.
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.SPECT.dicom.get_affine_spect(ds)[source]#
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)[source]#
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')[source]#
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 reconstructionmethod (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’]