cleanX.dicom_processing.pydicom_adapter module

class cleanX.dicom_processing.pydicom_adapter.PydicomDicomReader(exclude_field_types=None, date_fields=None, time_fields=None, exclude_fields=None)

Bases: object

Class for reading DICOM metadata with pydicom.

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

Initializes the reader with some filtering options.

Parameters:
  • exclude_field_types (Sequence[type]) –

    Some DICOM types have internal structure difficult to represent in a dataframe. These are filtered by default:

  • date_fields (Sequence[str]) – Fields that should be interpreted as having date information in them.

  • time_fields (Sequence[str]) – Fields that should be interpreted as having time information in them.

  • exclude_fields (Sequence[str]) – Fields to exclude (in addition to those selected by exclude_field_types

exclude_field_types = (<class 'pydicom.sequence.Sequence'>, <class 'pydicom.multival.MultiValue'>, <class 'bytes'>)

Default types of fields not to be included in the dataframe produced from parsed DICOM files.

date_fields = ('ContentDate', 'SeriesDate', 'ContentDate', 'StudyDate')

Default DICOM tags that should be interpreted as containing date information.

time_fields = ('ContentTime', 'StudyTime')

Default DICOM tags that should be interpreted as containing datetime information.

exclude_fields = ()

Default tags to be excluded from genrated DataFrame for any other reason.

dicom_date_to_date(source)

Utility method to help translate DICOM dates to date

Parameters:

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

Returns:

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

This function allows reading of metadata in what source gives.

Parameters:

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

Returns:

dataframe with metadata from dicoms

Return type:

DataFrame

cleanX.dicom_processing.pydicom_adapter.get_jpg_with_pydicom(dicom_folder_path, jpg_folder_path)

This function is for users with pydicom 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.

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

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

Returns:

love (will put your images in the new folder but not return them)

Return type:

bool