top of page


Author: Mounami Reddy Kayitha

What is fMRIPrep?

fMRIPrep, a Nipreps application, was developed as a functional magnetic resonance imaging preprocessing pipeline to help analyze task-based and resting-state fMRI images. fMRIPrep utilizes tools from FreeSurfer, AFNI, FSL, ANTS, and other preprocessing tools to:

Take fMRI data from raw to fully preprocessed form.

  • Implement tools from different software packages.

  • Optimize data processing

  • Preprocessing quality reports

  • Thorough output of preprocessing stages + errors

  • Automate + parallelize processing

Before we can install fMRIPrep, we first need to understand what BIDS is, as fMRIPrep requires the data to be organized in BIDS format.

What is BIDS?

Neuroimaging is a complex field, with millions of minds all working together to explore the various facets of the brain. But with the intelligence of millions of minds comes the chaos as well. Neuro-imagers have long tried to create a standardized system to organize neuroimaging data. But nothing ever became truly standardized.

Screen Shot 2022-07-05 at 12.28.08 PM.png

BIDS is that 15th standard. Well, not really but it's a really close accepted format even if it isn’t the standardized one. BIDS or Brain Imaging Data

Structures is an organizational structure to organize, annotate, and describe neuroimaging data, with a folder system and respective JSON files containing metadata (data with information about other data). The purpose of BIDS is to make it easier for researchers to format for data so it's easily accessible and understandable for others. A short list of the other benefits of BIDS are:

  • Same Vocabulary

  • Reproducibility

  • Easy to Share

  • Organized

  • Systematic

  • Applicable to Software

  • Easy to Adopt

  • Simple Structure

BIDS Origins:

BIDS was a collaborative project that started at a Stanford Lab in January 2015. Originally run by Chris Gorgolewski, the project is now spearheaded by a Steering Group, Franklin Feingold, Stefan Appelhoff, Chris Markiewicz, and Stanford’s Poldrack Lab ( BIDS was inspired by the format used in OpenfMRI (now

BIDS Specification Guidelines:

In order to convert to BIDS format, we need to follow the BIDS specifications guidelines that clearly document the formatting rules.

  1. Go to:

  2. Click on the embedded link on the page: downloaded as PDF (or go straight to

  3. Download the BIDS Specification Guidelines

I would recommend familiarizing yourself with the table of contents at the very least so that you can easily identify what guidelines are present and where you can find them.

BIDS Conversion:

Here's a brief set of instructions to convert to BIDS format.

MRICroGL Installation:

First things first, you need MRICroGL to be able to begin converting your data to BIDS. MRICroGL converts DICOM files to Nifti files and produces an accompanying JSON file.

To download MRICroGL:

Reminder: Make sure the version you are downloading is for your specific system.

Note: You may need to create an account to download.

MRICroGL Usage:

Once downloaded, launch MRICroGL. You should be greeted with a screen that looks similar to this::

Screen Shot 2022-07-05 at 12.34.45 PM.png

Now locate the import menu and click 'Convert DICOM to NifTI':

Screen Shot 2022-07-05 at 12.36.10 PM.png

This will bring you to a new page:

Screen Shot 2022-07-05 at 12.37.34 PM.png

In this new page:

  1. Under Output Directory: Change the location to where you wish your converted files to go.

  2. Under Create BIDS Sidecar: Make sure the option is set to ‘Yes, Anonymized’

  3. Drag and drop files/folders that you wish to convert (should be all of the folders in the data set which have DICOM data).

  4. Optional: You may delete the DICOM data if you feel you have no need for it.

BIDS Conversion:

  1. Create a folder for your data (typically with the BIDS label somewhere in the title).

  2. Create description_dataset.json file using, according to the BIDS Specification guidelines

  3. Create a folder hierarchy based on the BIDS Specification guidelines.

  4. Files should then be renamed according to the BIDS Specification guidelines and the folder hierarchy they are under.

  5. Utilize the BIDS Validator () to check for errors and fix them accordingly to ensure that the BIDS format is strictly upheld.

Note: this is not a thorough explanation of BIDS conversion, as the guidelines (located here: provide a far more thorough explanation for general formatting and specific cases as well).

  1. docker run hello-world (should give a message from docker tutorial page itself)

  2. Close and reopen docker to see hello-world under “images”


fMRIPrep Installation Steps:

Installation Video: 

Docker-Interactive Installation



  1. Install Docker (enter any passwords asked, etc.) (Choose download for respective processing system:

  2. The link also has a command line method to install docker if so preferred

  3. Should see the Docker icon at the top of the screen (upper right)

  4. Next Validate Install:

    1. Click on icon and should see a Docker Desktop is running message

    2. In Terminal or Command Prompt:

      1. docker (command should give you features of docker)

      2. docker run hello-world (should give a message from docker tutorial page itself)

      3. Close and reopen docker to see hello-world under “images”

fMRIPrep Installation(

  1. which pip

    1. If pip is not installed: for installation steps, go to

    2. python3 -m pip install fmriprep-docker

      1. When you run it again, it should just list the file path that fmriprep-docker is in​

    3. echo ‘export PATH=$PATH:/path of where fmriprep-docker is located' >> ~ /.bash_profile

      1. Such as: echo ‘export PATH=$PATH:/Users/mkayitha/.local/lib/Python3.9/site-packages’ >> ~ /.bash_profile​

    4. source ~ /.bash_profile

FreeSurfer License

Get a (free) FreeSurfer License ( in order to be able to use FreeSurfer tools when running fMRIPrep.

Note: You do not necessarily need to fill in all of the information in order to get the license, but preferably as much as possible.

Note: Save the license and note down the path for later.

fMRIPrep Preprocessing Basic Script:



#User inputs:




mem=20 #gb

container=docker #docker or singularity



#Convert virtual memory from gb to mb

mem=`echo "${mem//[!0-9]/}"` #remove gb at end

mem_mb=`echo $(((mem*1000)-5000))` #reduce some memory for buffer space during pre-processing

export TEMPLATEFLOW_HOME=$HOME/.cache/templateflow

export FS_LICENSE=$HOME/BIDS_fMRIPrep/derivatives/license.txt


#Run fmriprep

if [ $container == singularity ]; then

  unset PYTHONPATH; singularity run -B $HOME/.cache/templateflow:/opt/templateflow $HOME/fmriprep.simg \

    $bids_root_dir $bids_root_dir/derivatives \

    participant \

    --participant-label $subj \

    --skip-bids-validation \

    --md-only-boilerplate \

    --fs-license-file $FREESURFER_HOME/license.txt \

    --fs-no-reconall \

    --output-spaces MNI152NLin2009cAsym:res-2 \

    --nthreads $nthreads \

    --stop-on-first-crash \

    --mem_mb $mem_mb \

    -w $HOME


  fmriprep-docker $bids_root_dir $bids_root_dir/derivatives \

    participant \

    --participant-label $subj \

    --skip-bids-validation \

    --md-only-boilerplate \

    --fs-license-file $HOME/BIDS_fMRIPrep/BIDS/derivatives/license.txt \

    --fs-no-reconall \

    --output-spaces MNI152NLin2009cAsym:res-2 \

    --nthreads $nthreads \

    --stop-on-first-crash \

    --mem_mb $mem_mb \

    -w $HOME


*Note: This code was obtained from Andy's Brain Book ( and only slightly modified based on potential user preferences, as a base script to utilize to start preprocessing. The script will complete standard preprocessing steps including coregistration, normalization, and physiological component extraction 

fMRIPrep Preprocessing Steps:

The method to run the script is relatively simple, with only a few minor tweaks to the script as detailed in the proceeding steps:

Folder Hierarchy:

First, create a folder hierarchy system to organize all data.

  1. Create the main folder for all the related data and preprocessing data to go into.

  2. Create a subfolder for the code named ‘code’ (for simplicity).

  3. Move the BIDS organized data to the folder.

  4. Create a subfolder titled ‘derivatives’ in the BIDS folder system.

The folder should look similar to this:

Screen Shot 2022-07-12 at 6.12.23 PM.png

FreeSurfer License:

Now, to move the FreeSurfer license to the 'derivatives' folder

  1. First identify the path of your FreeSurfer license (you should have noted it down).

  2. Next, open your Terminal or Command Prompt.

  3. Ensure you are in the bash shell (change to bash shell if required).

  4. Enter the following command prompts to move the license to the created ‘derivative’ folder
    mv [path-of-license-file] [path-of-derivatives-folder]

    1. Note: Where it says [path-of-license-file], input the path of the license file. 

    2. Note: Where it says [path-of-derivatives-folder], input the path of the ‘derivatives’ folder where you want the FreeSurfer license file to be located 

      1. (such as:  mv ~/Downloads/license.txt   ~/Desktop/BIDS_fMRIPrep/BIDS/derivatives)

Create and Edit Script File:

  1. Enter the following command prompts to create and edit the file for the script.

    • touch [path-for-code-folder]/

      • Note: Where it says [path-for-code-folder], input the path of the ‘code’ folder where you want the script to be located (such as: touch $HOME/Desktop/BIDS_fMRIPrep/code/

    • vim []

      • Note: Where it says [], input the path (such as: vim $HOME/BIDS_fMRIPrep/code/

  2. You have now opened up the file to be edited.

    1. Press ‘i’.

    2. Paste the script into the file.

    3. Where it says  bids_root_dir under the block of code commented  #User inputs: , set the variable to the path of the folder system for where you want your data to go to (for ex: $HOME/BIDS_fMRIPRep/BIDS)

    4. Where it says fs-license-file under the Docker if-else block of code, input the FreeSurfer license path (such as: $HOME/BIDS_fMRIPRep/BIDS/derivatives/license.txt)

    5. Press ‘esc’. 

    6. Type ‘:wq’ to save and exit the file.

    7. In the command line, type cat [] (such as: cat $HOME/BIDS_fMRIPrep/code/

Note: You now should have the file in your derivatives folder. You may edit this file and change the code to add more specific parameters or processing steps or change the container. You may change the subj variable depending on which subject you wish to process.

Run the Script:

Enter bash in the command line to run the script

fMRIPrep Preprocessing Without Script:

Note: This command was derived from Stanford Center for Reproducible Neuroscience at

  1. Enter fmriprep-docker [path-to-BIDS-data-folder]  [path-to-derivatives-folder] participant --participant-label [participant label w/out ‘sub’ prefix] --fs-license-file [path-to-FreeSurfer-license-file]

    • Such as: fmriprep-docker ~/Desktop/BIDS_fMRIPrep/BIDS ~/Desktop/BIDS_fMRIPrep/BID/derivatives participant --participant-label 01 --fs-license-file ~/Desktop/BIDS_fMRIPrep/BIDS/derivatives/license.txtSuch as: 

You may add additional arguments after the input, output, and analysis levels (

A Few, Basic Preprocessing Tools:

  • Inputnode (utility): Anatomy sub-workflow that constructs an average image of T1w images to RAS orientation and common voxel size, or averages group images

    • -  Brain extraction

    • FSL fast - tissue segmentation

    • antsRegistration - spatial normalization

    • FreeSurfer mri_robust_template - merge multiple T1w images onto a single template

  • init_func_preproc_wf(): bold preprocessing

    • FSL mcflirt - estimates head motion

    • AFNI 3dTShift - slice time correction

Well, that's the end of this blog. is a valuable resource to use to look at all the other great features that fMRIPrep has and are soon to come!

bottom of page