Converting DICOM files to NIfTI Format

Purpose:

NIfTI is a commonly used neuroimaging data format. Many of the analysis software packages require input in NIfTI format. The raw data from most scanners, however, are in the industry standard DICOM format. Therefore, they should first be converted to NIfTI format. This document explains how to do this conversion. The procedure explained here produces a BIDS-compliant folder structure using sample data from our group. The filenames are kept simple for this specific example for compactness. For more proper naming see Storing & Sharing MR Studies, part of our group’s MR analysis pipeline. (Also see https://bids.neuroimaging.io/)

Description:

On your computer, create a folder ‘fMRI-HandsOn’. Under this folder, create the following three folders: ‘DICOM’, ‘NIFTI’, ‘results’

Download this sample dataset: https://drive.google.com/file/d/19TtgIT9OmeIThzhVFwpvbQYF7RnnmA4h/view?usp=sharing

Extract its content under the DICOM folder. (You may have a hierarchy with several subfolders after extracting the contents. In the end make sure that your folder structure looks like the one below)

dicom-folder

Under the NIFTI folder, create a new folder ‘sub-01’. Under sub-01, create three new folders: ‘func’, ‘anat’, ‘fmap’

nifti-folder

Download and open MRICroGL (accept the License agreement and download the zip file; then extract its content under a folder. Double click on the MRICroGL program inside that folder)

On MRICroGL, click on import and convert DICOM to NIfTI

import-convert-dicom-to-nifti

On the new “dcm2nixx DICOM to NIfTI conversion” window, edit the output file name as sub-01_T1w

output-file-name

For Output Directory, choose the NIFTI/sub-01/anat folder

Next, select a folder to convert. This button is at the bottom of the left column

select-folder-to-convert

On the browser window, choose the T1 source folder under DICOM

folder-to-convert

Click Open. This should convert all the DICOM files under the T1 folder to NIfTI format, and place the NIFTI file under the anat folder. Go back to the MRICroGL main window. Go to File – Open, and open the newly created nifti file. Inspect the images.

Note that the conversion creates a JSON file, too. Open and inspect that file with a text editor.

The NIFTI file created this way will have the facial features visible. You MUST de-face this image. Using software (e.g. pydeface) de-face the image. Replace the original (with face) image with the de-faced one. The original (with face) image MUST be deleted, and never shared with the world.

anat-folder

For the functional data, follow the same procedure. Open MRIcroGL, click on import and convert DICOM to NIFTI

For output filename enter: sub-01_task-motor_bold

For Output Directory choose NIFTI/sub-01/func

Select the motor scan folder to convert

folder-to-convert-func-motor

Click Open. This should convert all the DICOM files under the MOCOSERIES_0004 folder to NIfTI format, and place the NIfTI file under the func folder. Open and inspect the NIFTI file with MRICroGL. Click on various voxels and inspect the time course of the BOLD response shown at the bottom panel.

Note that the conversion creates a JSON file, too

motor-nifti-file

Open and edit the JSON file to include the following line

"TaskName": "Motor Task",

motor-json

Apply the same procedures to convert the vision run DICOM files into NIFTI:
Output file name: sub-01_task-vision_bold
Output Directory: NIFTI/sub-01/func
folder to convert: DICOM/MOCOSERIES_0006

After the conversion is complete edit the sub-01_task-vision_bold.json file to include

"TaskName": "Vision Task",

Finally, the fieldmaps: Open MRIcroGL, click on import and convert DICOM to NIFTI

Output filename: sub-01_dir-AP_epi
Output Directory: NIFTI/sub-01/fmap
Select folder to convert: DICOM/CMRR_MBEP2D_SE_TOPUP_A2P_MB4_0007

Repeat the same procedure for the other direction

Output filename: sub-01_dir-PA_epi
Output Directory: NIFTI/sub-01/fmap
Select folder to convert: DICOM/CMRR_MBEP2D_SE_TOPUP_P2A_MB4_0008

This completes the DICOM to NIfTI conversion. To make the folder BIDS-compliant, and make the files ready for further analyses a few more steps are needed.

First, read and get familiar with the information here: https://github.com/bids-standard/bids-starter-kit. Especially this one: https://bids-specification.readthedocs.io/en/stable/01-introduction.html

Further, read our lab’s procedures for Storing & Sharing MR Studies.

BIDS will require a dataset_description.json file in the NIfTI folder. A minimal file can be something like

{
    "Name":"fMRI-Demo",
    "BIDSVersion":"1.0.2",
    "Authors":["Beyza Akkoyunlu","Huseyin Boyaci"]
}

“Name” and “BIDSVersion” are required fields by BIDS. A more detailed description file would be better (see this example). For example, how is your dataset licensed? Can everyone use it? Under what conditions? If there is one, what is the DOI?

It is optional, but you can have plain text, human-readable README file describing the data under the NIfTI folder. For example

NSC672, Fall 2021

NIFTI files for the vision and motor experimental scans under the Block design, GLM study for the NSC672 class (project).

These data are collected over two weeks for the Module 4 component of the course. 

With the intention of using them for level-1, level-2 and level-3 analysis. 

Two participants' data were collected.

BIDS does not require but recommends events files for corresponding task fMRI scans. There are two such files for each task scan. One is a tsv file showing the event onsets and duration, second one is json file describing the columns in the tsv file. Here is the events file for the motor task, sub-01_task-motor_events.tsv

onset    duration    task
0    14    rest
14    12    right
26    12    left
38    12    rest
50    12    both
62    12    left
74    12    right
98    12    both
110    12    right
122    12    left
134    12    rest
146    12    both
158    12    left
170    12    right
182    12    rest
194    12    both
206    12    right
218    12    left
230    12    rest
242    12    both
254    12    left
266    12    right
278    12    rest
290    12    both
302    12    right
314    12    left
326    12    rest
338    12    both
350    12    left
362    12    right
378    12    rest
386    12    both
398    12    right
410    12    left
422    12    rest
434    12    both
446    12    left
458    12    right
470    12    rest
482    12    both
494    12    right
506    12    left
518    12    rest
530    12    both
542    12    left
554    12    right
566    12    rest
578    12    both

and here is the corresponding json file, sub-01_task-motor_events.json

{
    "task": {
        "LongName": "Task side",
        "Description": "Which hand moved",
        "Levels": {
          "left": "Left hand squeeze",
          "right": "Right hand squeeze",
          "both": "Both hand squeeze",
          "rest": "No hand squeeze"
        }
      }
}

Note that the onset and duration columns are REQUIRED. Any number of additional columns MAY be added.

For later analyses, you need to tell fsl what the fieldmap files will be used for. This is done by adding the following at the beginning of sub-01_dir-AP_epi.json and sub-01_dir-PA_epi.json files

"IntendedFor":["func/sub-01_task-motor_bold.nii.gz","func/sub-01_task-vision_bold.nii.gz"]

dir-AP-epi-json

Finally, check whether your NIfTI folder is BIDS-compliant using the online BIDS validator: https://bids-standard.github.io/bids-validator/

Note:

I have outlined the procedure using MRIcroGL above. You SHOULD streamline your conversion using scripts. For basics of scripting see http://reproducibility.stanford.edu/bids-tutorial-series-part-1b. When I have time, I will prepare and upload a sample script for the pipeline we use in CBVG.