🚀 We're looking for ML Engineers and Medical Reviewers! Join the OpenPHR Mission →
Tutorial

Introduction to the BIDS Standard for Neuroimaging

Difficulty: Beginner Time: 10 min read

Introduction

The Brain Imaging Data Structure (BIDS) is a simple and intuitive way to organize and describe your neuroimaging and behavioral data. In this guide, we will walk through the basics of converting a raw MRI dataset into a BIDS-compliant format suitable for machine learning pipelines.

Prerequisites

  • Python 3.8+
  • Raw DICOM neuroimaging files
  • dcm2niix installed

Step 1: Convert DICOM to NIfTI

Most machine learning models (like 3D CNNs or MedSAM) require NIfTI (.nii or .nii.gz) files rather than raw DICOMs. We use dcm2niix to perform this conversion while creating the necessary JSON sidecar files for BIDS.

dcm2niix -z y -f %p_%s -o ./nifti_output ./raw_dicoms

Step 2: Understand the BIDS Directory Structure

A BIDS-compliant dataset follows a strict hierarchical folder structure. Here is a basic example:

my_dataset/
├── dataset_description.json
├── participants.tsv
├── sub-01/
│   ├── anat/
│   │   ├── sub-01_T1w.nii.gz
│   │   └── sub-01_T1w.json
│   └── func/
│       ├── sub-01_task-rest_bold.nii.gz
│       └── sub-01_task-rest_bold.json
└── sub-02/
    └── anat/
        ├── sub-02_T1w.nii.gz
        └── sub-02_T1w.json

Step 3: Validate Your Dataset

Before publishing your dataset or feeding it into a pipeline like fMRIPrep, you should always validate it using the BIDS Validator.

npm install -g bids-validator
bids-validator my_dataset/

Conclusion

Adopting the BIDS standard ensures that your medical imaging datasets are interoperable, reproducible, and ready to be consumed by the open-source machine learning community.