You want to 3D print your or another ones brain? Here's a step by step guide on how to end up with a 3D-printable brain model. It's as easy as running two command lines. This is an adaptation and extension of skjerns/3dprintedbrain_docker and miykael/3dprintyourbrain with more options, ease of use and enhanced anatomical accuracy.
What you need
- Structural brain image (T1-weighted) in NIfTI-format
- FreeSurfer license (it's free; see Installation)
- Installation of 'Docker Desktop' (see Installation)
- 21 GB of free disk space
- Simple installation and usage - just two commands to get started.
- Compatible with pre-existing FreeSurfer [7.3+] output.
- Enhanced anatomical accuracy by leveraging both FreeSurfer's 'recon-all' and 'segment_subregions' pipelines, as well as by integrating ventricles.
- Generates print-ready STL files for subcortical structures, cortical regions, and the whole brain.
- Option to create a separate STL file for each hemisphere.
- [BETA] Option to generate STL files for parcels of the Desikan-Killiany Atlas and brain lobes.
- [BETA] Option to generate STL file for cerebral white matter.
- Smaller Docker image (20.46 GB)
- Technical feature: No longer requires FSL as a dependency (saving 10 GB of space).
- Technical feature: Runs entirely from a single Python file.
Register on the Harvard FreeSurferWiki with your email and get a free Freesurfer 'license.txt' file.
Download and install Docker Desktop. It is free of charge and availabe for Mac, Windows and Linux.
Option A: via Terminal
Open the terminal and run: docker image pull lbutry/nii2stl:latest
Option B: via Docker Desktop app
- Open 'Docker Desktop'
- Navigate to the search bar at the top and type 'lbutry/nii2stl'.
- Click on 'Pull' to download the image.
Option C: Build manually from this repository
- Clone this repository
- Open the repository folder with the terminal
- Run
docker build -t nii2stl .
- Create a new folder (e.g. named 'home')
- Copy your FreeSurfer 'license.txt' file and your brain T1w image (.nii or .nii.gz) into the folder.
Note
The following instructions assume that your brain T1w image is named 'brain.nii.gz'. If your file has a different name, please adjust the commands accordingly.
- Navigate inside the terminal to the folder:
cd /path/to/folder - Run the command below:
Usage docker run -t -v ./:/app/share <image name> <options>
Example for default use
- Mac/Linux:
docker run -t -v ./:/app/share lbutry/nii2stl -t1w brain.nii.gz - Windows:
docker run -t -v .\/:/app/share lbutry/nii2stl -t1w brain.nii.gz
Tip
The default run will take several hours to complete due to FreeSurfer's 'recon-all' processing time. If you already have FreeSurfer output, consider using the -fs_skip option to skip this step.
Example using additional options
All options are listed at section Arguments and options. If you want to skip FreeSurfer (-fs_skip), use custom brainstem smoothing (-smoothing) and obtain an STL file for each hemisphere (-hemi), use the following command:
- Mac/Linux:
docker run -t -v ./:/app/share lbutry/nii2stl -fs_skip -smoothing 0 -hemi - Windows:
docker run -t -v .\/:/app/share lbutry/nii2stl -fs_skip -smoothing 0 -hemi
General options
-workKeep work directory.-tag <tag>If set,_<tag>is appended to the output and FreeSurfer folder. When-fs_skipis additionally set, the FreeSurfer output directory with the according tag is used. [Defaut: None]
Tip
Use the -tag option to keep multiple outputs organised. For example, if you want to use nii2stl on different T1w images, you can run the script multiple times with different -tag values. Each output will be saved in a separate folder. Also handels pre-existing FreeSurfer output.
Mandatory for default use
-t1w <file name>Name of the T1w-image (.nii or .nii.gz) inside the home directory.
Freesurfer options
-fs_skipSkip FreeSurfer's 'recon-all' pipeline. Checks if 'segment_subregion brainstem' needs to be run. Requires FreeSurfer output to be located in home directory.-fs_dir <folder name>Name of FreeSurfer output directory. [Default = freesurfer]"-fs_flags <flags>Parse more flags to recon-all.
Optional modules
-hemiCreate STL-file for each hemisphere. Including brainstem, cerebellum and corpus callosum.-parcels[BETA] Create STL-file for each parcel of the Desikan-Killiany Atlas and for each brain lobe.-wm[BETA] Create STL-file for cerebral white matter.
Mesh processing options
-smooth <int>Number of smoothing steps for subcortical model. Use '0' to disable. [Default = 150]-decimate <float>Target number of faces. Use '0' to disable. [Default = 200000]-planeoffsetIndicate where the subcotical model is cut in half on the x-axis. Only applicable when -hemi is set.-rev_overlap_correctionSwap subtraction terms in hemi overlap correction. Only applicable when -hemi is set.
All outputs are saved in the home directory.
home/freesurfer/...Segmentation output of FreeSurfer.home/output/brain_final.stl3D-printable STL model of the whole brain.home/output/cortical_final.stl3D-printable STL model of the cerebrum.home/output/subcortical_final.stl3D-printable model of the brainstem and cerebellum.home/output/hemi/...3D-printable STL model for both hemispheres.home/output/lobes/...3D-printable STL model for each brain lobe.home/output/parcels/...3D-printable STL model for each parcel of the Desikan-Killiany Atlas.
Q1: My MR images are in DICOM format and not in .nii or nii.gz.
- You can convert DICOM to NIfTI using dcm2niix.
Q2: I already have the output of FreeSurfer's 'recon-all'. How can I use it?
- Copy the FreeSurfer output folder to the home directory.
- Now you have two options:
- (a) Rename the folder to 'freesurfer' (or 'freesurfer_>tag<' when using the
-tagflag). - (b) Use the
-fs_dirflag to specify the name of your FreeSurfer output directory.
- (a) Rename the folder to 'freesurfer' (or 'freesurfer_>tag<' when using the
- Use the
-fs_skipoption to skip the 'recon-all' pipeline.
Q3: I already have the output of FreeSurfer 'recon-all' but not of 'segment_subregion brainstem'.
- Just follow the instructions of Q2 and use the
-fs_skipoption. The script will check if 'segment_subregion brainstem' needs to be run and do it if necessary.