Module that provides tools to convert DICOM files.

pydcmio.dcmconverter.converter.add_meta_to_nii(nii_file, dicom_dir, dcm_tags, outdir, prefix='f', additional_information=None)[source]

Add dicom tags to Nifti1 image header.

All selected dicom tag values are set in the ‘descrip’ Nifti header field.

Parameters:

nii_file: str

The nifti image to fill.

dicom_dir: str

The directory containing the dicoms used to generate the nifti image. We assume here that this folder contains only Dicom files.

dcm_tags: list

A list of 3-uplet of the form (name, tag, stack_values) that will be inserted in the ‘descrip’ Nifti header field. If we want to stack all the Dicom dataset values, the ‘stack_values’ option mist be set to True.

outdir: str

The destination folder.

prefix: str (optional, default ‘f’)

The output image name prefix.

additional_information: dict (optional, default None)

A free dictionary items to be inserted in the ‘descrip’ image header field.

Returns:

filled_nii_file: str

The nifti image with filled header.

pydcmio.dcmconverter.converter.dcm2nii(input, o, b)[source]

Dicom to nifti conversion using ‘dcm2nii’.

You can specify all the ‘dcm2nii’ command options as input function parameters.

The basic usage is: dcm2nii <options> <sourcenames>

Options: a Anonymize [remove identifying information]: Y,N = Y b load settings from specified inifile, e.g. ‘-b C:set 1.ini’ d Date in filename [filename.dcm -> 20061230122032.nii]: Y,N = N e events (series/acq) in filename [filename.dcm -> s002a003.nii]: Y,N = N f Source filename [e.g. filename.par -> filename.nii]: Y,N = N g gzip output, filename.nii.gz [ignored if ‘-n n’]: Y,N = Y i ID in filename [filename.dcm -> johndoe.nii]: Y,N = N n output .nii file [if no, create .hdr/.img pair]: Y,N = Y o Output Directory, e.g. ‘C:TEMP’ (if unspecified, source directory is used) p Protocol in filename [filename.dcm -> TFE_T1.nii]: Y,N = Y r Reorient image to nearest orthogonal: Y,N s SPM2/Analyze not SPM5/NIfTI [ignored if ‘-n y’]: Y,N = N t Text report (patient and scan details): Y,N = N v Convert every image in the directory: Y,N = Y x Reorient and crop 3D NIfTI images: Y,N = N

Returns:

files: list of str

the converted files in nifti format.

reoriented_files: list of str

the reoriented converted files in nifti format.

reoriented_and_cropped_files list of str

the reoriented and cropped converted files in nifti format.

bvecs: list of str

the diffusion directions.

bvals: list of str

the diffusion acquisiton b-values.

pydcmio.dcmconverter.converter.dcm2niix(input, o, f='%p', z='y', b='y')[source]

Dicom to nifti conversion using ‘dcm2nii’.

You can specify all the ‘dcm2niix’ command options as input function parameters.

The basic usage is: dcm2niix [options] <in_folder>

Options: b: BIDS sidecar (y/n, default n) f: filename (%a=antenna (coil) number, %c=comments, %d=description, %e echo number, %f=folder name, %i ID of patient, %m=manufacturer, %n=name of patient, %p=protocol, %s=series number, %t=time, %u=acquisition number, %z sequence name; default ‘%f_%p_%t_%s’) h: show help m: merge 2D slices from same series regardless of study time, echo, coil, orientation, etc. (y/n, default n) o: output directory (omit to save to input folder) s: single file mode, do not convert other images in folder (y/n, default n) t: text notes includes private patient details (y/n, default n) v: verbose (y/n, default n) x: crop (y/n, default n) z: gz compress images (y/i/n, default n) [y=pigz, i=internal, n=no]

Returns:

files: list of str

the converted files in nifti format.

bvecs: list of str

the diffusion directions.

bvals: list of str

the diffusion acquisiton b-values.

bids: str

BIDS sidecar.

pydcmio.dcmconverter.converter.generate_config(niidir, anonymized=True, gzip=True, add_date=True, add_acquisition_number=True, add_protocol_name=True, add_patient_name=True, add_source_filename=True, begin_clip=0, end_clip=0)[source]

Generate a dcm2nii configuration file that disable the interactive mode.

Parameters:

niidir: str

The nifti destination folder.

anonymized: bool (optional, default True)

If ‘True’ then patient name will not be copied to NIfTI header.

gzip: bool (optional, default True)

If ‘True’ then dcm2nii will create compressed .nii.gz files.

add_date: str (optional, default True)

If ‘True’ then dcm2nii will add the requested element in the output filename.

add_acquisition_number: str (optional, default True)

If ‘True’ then dcm2nii will add the requested element in the output filename.

add_protocol_name: str (optional, default True)

If ‘True’ then dcm2nii will add the requested element in the output filename.

add_patient_name: str (optional, default True)

If ‘True’ then dcm2nii will add the requested element in the output filename.

add_source_filename: str (optional, default True)

If ‘True’ then dcm2nii will add the requested element in the output filename.

begin_clip: int (optional, default 0)

Specifies number of volumes to be removed from the beginning of a 4D acquisition.

end_clip: int (optional, default 0)

Specifies number of volumes to be removed from the end of a 4D acquisition.

Returns:

config_file: str

A dcm2nii configuration file written in the input ‘niidir’ folder.