cleanX.dicom_processing.simpleitk_adapter module

class cleanX.dicom_processing.simpleitk_adapter.MetadataHelper(reader)

Bases: object

Class for getting DICOM metadata with SimpleITK.

__init__(reader)

Initializes this helper with the instance of SimpleITK.ImageFileReader

Parameters:

reader (SimpleITK.ImageFileReader) – The SimpleITK redader used to read DICOM to extract metadata.

fetch_metadata(dicom_file)

Reads enough of the DICOM file to fetch its metadata.

Parameters:

dicom_file (str) – The file for which to read the metadata.

Returns:

Parsed metadata.

Return type:

dict

fetch_image(dicom_file)

Read the pixel data of the DICOM image.

Parameters:

dicom_file (str) – The file to extract image data from.

Returns:

Pixel array of the extracted image.

Return type:

ndarray

class cleanX.dicom_processing.simpleitk_adapter.SimpleITKDicomReader(date_fields=None, time_fields=None, exclude_fields=None)

Bases: object

Class for reading DICOM metadata with SimpleITK.

__init__(date_fields=None, time_fields=None, exclude_fields=None)

Initializes this reader with flags.

Parameters:
  • date_fields (Iterable) – Overrides the default values from date_fields.

  • time_fields – Overrides the default values from time_fields.

  • exclude_fields (Iterable) – Overrides the default values from exclude_fields.

date_fields = {'Content Date', 'Series Date', 'Study Date'}

Default fields in the parsed DICOM file to be interpreted as date.

time_fields = {'Content Time', 'Study Time'}

Default fields in the parsed DICOM file to be interpreted as datetime.

exclude_fields = {}

Default fields to exclude from dataframe generated form DICOM files.

dicom_date_to_date(source)

Utility method to parse DICOM dates to Python’s date.

Parameters:

source (str) – DICOM date given as string.

Returns:

Pyton date object.

Return type:

date.

dicom_time_to_time(source)

Utility method to help translate DICOM date and time objects to python datetime.

Warning

This isn’t implemented yet. Needs research on DICOM time representation.

Parameters:

source (str) – Date and time stored in DICOM as a string.

Returns:

Python’s datetime object.

Return type:

datetime

rip_out_jpgs(source, destination)

Extract image data from DICOM files and save it as JPG in destination.

Parameters:
  • source (Source) – A source generator. For extended explanation see Source.

  • destination (Compatible with os.path.join()) – The name of the directory where JPG files should be stored.

read(source)

Read DICOM files, parse their metadata, generate a DataFrame based on that metadata.

Parameters:

source (Source) – A source generator. For extended explanation see Source.

Returns:

dataframe with metadata from dicoms

Return type:

DataFrame

cleanX.dicom_processing.simpleitk_adapter.rip_out_jpgs_sitk(dicomfile_directory, output_directory)

This function is for users with simpleITK library only. If you do not have the library it will throw an error. The function function jpeg files out of a dicom file directory, one by one, each of them (not just the first series as), and puts them in an out put directory. It also returns the images for inspection (as arrays), which you can look at the [0] layer with matplotlib

Parameters:
  • dicomfile_directory (str) – dicomfile_directory, directory with dicom/.dcm

  • output_directory (str) – output_directory, where they should be placed

Returns:

List of images represented as NumPy arrays.

Return type:

List[numpy.ndarray]