pytomography.io.SPECT.dicom
#
Module Contents#
Functions#
Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file. |
|
|
Gets PyTomography metadata from a .dcm file. |
|
Gets 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. |
|
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. |
|
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 |
|
Converts a sequence of DICOM CT files (corresponding to a single scan) into a torch.Tensor object usable as an attenuation map in PyTomography. |
|
Computes an affine matrix corresponding the coordinate system of a SPECT DICOM file of projections. |
|
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. |
|
Saves the reconstructed object object to a series of DICOM files in the folder given by save_path. Requires the filepath of the projection data file_NM to get Study information. |
- pytomography.io.SPECT.dicom.parse_projection_dataset(ds)[source]#
Gets projections with corresponding radii and angles corresponding to projection data from a DICOM file.
- Parameters:
ds (Dataset) – pydicom dataset object.
- Returns:
Returns (i) projection data (ii) angles (iii) radii and (iv) flags for whether or not multiple energy windows/time slots were detected.
- Return type:
(torch.tensor[EWindows, TimeWindows, Ltheta, Lr, Lz], np.array, np.array)
- pytomography.io.SPECT.dicom.get_metadata(file, index_peak=0)[source]#
Gets PyTomography metadata from a .dcm file.
- Parameters:
file (str) – Path to the .dcm file of SPECT projection data.
index_peak (int) – EnergyWindowInformationSequence index corresponding to the photopeak. Defaults to 0.
- Returns:
Required metadata information for reconstruction in PyTomography.
- Return type:
- pytomography.io.SPECT.dicom.get_projections(file, index_peak=None, index_time=None)[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
- 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.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(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:
- pytomography.io.SPECT.dicom.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
- pytomography.io.SPECT.dicom.get_attenuation_map_from_CT_slices(files_CT, file_NM=None, index_peak=0, keep_as_HU=False, mode='constant')[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.dicom._get_affine_spect_projections(filename)[source]#
Computes an affine matrix corresponding the coordinate system of a SPECT DICOM file of projections.
- Parameters:
ds (Dataset) – DICOM dataset of projection data
filename (str) –
- Returns:
Affine matrix
- Return type:
np.array
- pytomography.io.SPECT.dicom._get_affine_CT(filenames)[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
filenames (Sequence[str]) –
- 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’]
- pytomography.io.SPECT.dicom.save_dcm(save_path, object, file_NM, recon_name='', scale_factor=1024)[source]#
Saves the reconstructed object object to a series of DICOM files in the folder given by save_path. Requires the filepath of the projection data file_NM to get Study information.
- Parameters:
object (torch.Tensor) – Reconstructed object of shape [1,Lx,Ly,Lz].
save_path (str) – Location of folder where to save the DICOM output files.
file_NM (str) – File path of the projection data corresponding to the reconstruction.
recon_name (str) – Type of reconstruction performed. Obtained from the recon_method_str attribute of a reconstruction algorithm class.
scale_factor (float, optional) – Amount by which to scale output data so that it can be converted into a 16 bit integer. Defaults to 1024.
- Return type:
None