Skip to content

dicom2df Module

dicom2df Module

This module contains functions used to transform DICOM files into a single pandas DataFrame. It opens each file with pydicom, and flats the DICOM nested structure before saving it to the dataFrame.

dicom2df(search_dir, with_private=False, with_pixels=False, with_seqs=True)

Create a pandas DataFrame based on a directory of DICOM files

This function creates

Parameters:

Name Type Description Default
search_dir str

Path to the directory containing the DICOM files.

required
with_private bool

Whether to include Private DICOM tags in the dataframe or not.

False
with_pixels bool

Whether to include pixel bytes (PixelData attribute) in the produced the dataFrame or not. Default to false as it has an important impact on performance.

False
with_seqs bool

Whether to include DICOM sequences of attributes in the produced dataFrame or not.

True

Returns:

Type Description
DataFrame

A dataframe with information of all DICOM files present in search_dir.

Example

In the following example, we have a directory containing a single DICOM file.

dicom2df_single_file.py
1
2
3
from deidcm.dicom.dicom2df import dicom2df

dicom2df(search_dir='/path/to/dcm-dir')

In the output of the command, we can see the number of files that have been read correctly and then the dataframe containing all DICOM files information.

06-26-2024 15:10:18 Successfully retrieved file(s): 1
06-26-2024 15:10:18 Unreadable file(s): 0
FileMetaInformationGroupLength_0x00020000_UL_1____  ...      FilePath
0                                                208  ...  ./cmmd-1.dcm

[1 rows x 101 columns]