pytomography.io.shared#

Shared functionality between different imaging modalities.

Submodules#

Package Contents#

Functions#

create_ds(reference_ds, SOP_instance_UID, ...)

Creates a new DICOM dataset based on a reference dataset with all required headers. Because this is potentially used to save images corresponding to different modalities, the UIDs must be input arguments to this function. In addition, since some modalities require saving multiple slices whereby SOP_instance_UIDs may use some convention to specify slice number, these are also input arguments.

get_header_value(list_of_attributes, header[, dtype, ...])

Finds the first entry in an Interfile with the string header

get_attenuation_map_interfile(headerfile)

Opens attenuation data from SIMIND output

open_multifile(files[, return_object_meta])

Given a list of seperate DICOM files, opens them up and stacks them together into a single CT image.

open_singlefile(file)

Opens data from a single DICOM file.

align_images_affine(im_fixed, im_moving, affine_fixed, ...)

_get_affine_multifile(files)

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).

_get_affine_single_file(filename)

Obtain the affine matrix from a 3D medical image stored in a single file.

pytomography.io.shared.create_ds(reference_ds, SOP_instance_UID, SOP_class_UID, modality, imagetype)[source]#

Creates a new DICOM dataset based on a reference dataset with all required headers. Because this is potentially used to save images corresponding to different modalities, the UIDs must be input arguments to this function. In addition, since some modalities require saving multiple slices whereby SOP_instance_UIDs may use some convention to specify slice number, these are also input arguments.

Parameters:
  • reference_ds (FileDataset) – Dataset from which to copy all important headers such as patient information and study UID.

  • SOP_instance_UID (str) – Unique identifier for the particular instance (this is different for every DICOM file created)

  • SOP_class_UID (str) – Unique identifier for the imaging modality

  • modality (str) – String specifying imaging modality

  • imagetype (str) – String specifying image type

Returns:

_description_

Return type:

_type_

pytomography.io.shared.get_header_value(list_of_attributes, header, dtype=np.float32, split_substr=':=', split_idx=-1, return_all=False)[source]#

Finds the first entry in an Interfile with the string header

Parameters:
  • list_of_attributes (list[str]) – Simind data file, as a list of lines.

  • header (str) – The header looked for

  • dtype (type, optional) – The data type to be returned corresponding to the value of the header. Defaults to np.float32.

Returns:

The value corresponding to the header (header).

Return type:

float|str|int

pytomography.io.shared.get_attenuation_map_interfile(headerfile)[source]#

Opens attenuation data from SIMIND output

Parameters:

headerfile (str) – Path to header file

Returns:

Tensor containing attenuation map required for attenuation correction in SPECT/PET imaging.

Return type:

torch.Tensor[batch_size, Lx, Ly, Lz]

pytomography.io.shared.open_multifile(files, return_object_meta=False)[source]#

Given a list of seperate DICOM files, opens them up and stacks them together into a single CT image.

Parameters:
  • files (Sequence[str]) – List of CT DICOM filepaths corresponding to different z slices of the same scan.

  • return_object_meta (bool) – Whether or not to return object metadata corresponding to opened file

Returns:

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

Return type:

np.array

pytomography.io.shared.open_singlefile(file)[source]#

Opens data from a single DICOM file.

Parameters:

file (str) – Filepath

Returns:

3D Image

Return type:

torch.Tensor

pytomography.io.shared.align_images_affine(im_fixed, im_moving, affine_fixed, affine_moving, cval=0)[source]#
pytomography.io.shared._get_affine_multifile(files)[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

  • files (Sequence[str]) –

Returns:

Affine matrix corresponding to CT scan.

Return type:

np.array

pytomography.io.shared._get_affine_single_file(filename)[source]#

Obtain the affine matrix from a 3D medical image stored in a single file.

Parameters:

filename (str) – Path of file

Returns:

Affine matrix

Return type:

np.array