Skip to content

df2dicom Module

df2dicom Module

This module contains functions used to transform a pandas DataFrame into DICOM and PNG files. It can build a valid DICOM file by obtaining the pixels and DICOM attributes from the DataFrame.

df2dicom(df, outdir, do_image_deidentification=False, test=False, output_file_formats=None)

Build DICOM and/or PNG files from a pandas DataFrame obtained with dicom2df.

Parameters:

Name Type Description Default
df DataFrame

The pandas DataFrame obtained with dicom2df that you want to convert back to DICOM/PNG files.

required
outdir str

Path of the directory that will contain your files at the end of the process.

required
do_image_deidentification bool

Whether or not this process will trigger the OCR deidentification for pixels.

False
test bool

This option should not be left to False anytime.

False
output_file_formats list

A list of formats. Currently supported formats are ["dcm", "png"]. Both can be used alone if you need a single output format. If you select "png", the process will produce a PNG for each line of df

None
Example

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

deidentify_attributes_and_pixels.py
1
2
3
4
5
6
7
8
9
from deidcm.dicom.df2dicom import df2dicom
from deidcm.dicom.deid_mammogram import deidentify_attributes

# First part of the deidentification process (Attribute deidentification)
df = deidentify_attributes(indir='/path/to/indir', outdir='/path/to/outdir', org_root='15681.1344456.1444', erase_outdir=False)
df.to_csv(os.path.join(outdir, 'meta.csv'))

# Second part of the deidentification process (OCR deidentification)
df2dicom(df, outdir='/path/to/outdir_folder', do_image_deidentification=True)

Here is an overview of the resulting files in the output directory:

outdir/
├── meta.csv
└── 15681.1344456.1444.150859203650428010901213750509.png

Example

It is also possible to obtain only DICOM files:

only_dcm_files.py
1
2
3
...
df = deidentify_attributes(indir='/path/to/indir', outdir='/path/to/outdir', org_root='15681.1344456.1444', erase_outdir=False, output_file_formats = ["dcm"])
...

Output directory:

outdir/
└── 15681.1344456.1444.150859203650428010901213750509.dcm

it is also possible to obtain DICOM and PNG files:

only_dcm_files.py
1
2
3
4
...
df = deidentify_attributes(indir='/path/to/indir', outdir='/path/to/outdir', org_root='15681.1344456.1444', erase_outdir=False, output_file_formats = ["dcm", "png"])
df.to_csv(os.path.join(outdir, 'meta.csv'))
df2dicom(df, outdir='/path/to/outdir_folder', do_image_deidentification=True)

Output directory:

outdir/
├── meta.csv
├── 15681.1344456.1444.150859203650428010901213750509.png
└── 15681.1344456.1444.150859203650428010901213750509.dcm