• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created almost 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

How to create fancy GIFs from an MRI brain image

GitHub issues GitHub pull-requests GitHub contributors GitHub Commits GitHub size

Gif your nifti

Create nice looking gifs from your nifti (.nii or .nii.gz) files with a simple command:

gif_your_nifti /path/to/data.nii

Getting started

Dependencies

Package Tested version
NumPy 1.14.2
NiBabel 2.2.1
matplotlib 2.2.0
imageio 2.2.0
scikit-image 0.13.0

Installation

The quickest method is to install directly from GitHub:

pip install git+https://github.com/miykael/gif_your_nifti.git

Alternately, navigate to the main page of the repository and clone it. Then, change directory to the cloned repository and run:

pip install .  # If you're not making changes
# or
pip install -r requirements.txt  # If you're a developer

Docker

Build a docker container with:

docker build -t gif_your_nifti .

Run with docker:

docker run --rm -v /path/to/nifti/:/data gif_your_nifti:latest /data/image.nii

Examples

For the examples below, I've downloaded ICBM 2009c Nonlinear Asymmetric and used the T1 and gray matter template thereof.

It is also possible to use your own brain image, as I will show below. The only thing that you need to make sure is, that your brain image has the right orientation. You can reorient your NIfTI image according to the MNI template standard with the FSL command: fslreorient2std my_brain.nii my_brain.nii.

Grayscale GIF

To create a simple gray scale gif, type the following command in your commandline:

gif_your_nifti /path/to/mni_icbm152_t1_tal_nlin_asym_09c.nii

Pseudocolor GIF

To create a pseudocolor gif, type the following command in your commandline:

gif_your_nifti /path/to/Me_2014.nii --mode pseudocolor --cmap plasma

The colormap can be any colormap from the matplotlib colormaps.

Depth GIF

To create a depth gif, type the following command in your commandline:

gif_your_nifti /path/to/mni_icbm152_t1_tal_nlin_asym_09c.nii --mode depth

The image shows you in color what the value of the next slice will be. If the color is slightly red or blue it means that the value on the next slide is brighter or darker, respectifely. It therefore encodes a certain kind of depth into the gif.

RGB GIF

To create a Red Blue Green (RGB) gif, type the following command in your commandline:

gif_your_nifti /path/to/gm.nii /path/to/wm.nii /path/to/csf.nii --mode rgb

This image takes the values from the first NIfTI file as its red colors, second NIfTI file as its green colors and third NIfTI as its blue colors.

Resize GIF

It is also possible to change the size of a gif, by changing the size parameter in any function above. The following are examples of resizing the images to 50% of it's original size, with:

gif_your_nifti /path/to/mni_icbm152_gm_tal_nlin_asym_09c.nii --size 0.5
gif_your_nifti /path/to/mni_icbm152_gm_tal_nlin_asym_09c.nii --size 0.5 --mode pseudocolor --cmap cubehelix
gif_your_nifti /path/to/mni_icbm152_gm_tal_nlin_asym_09c.nii --size 0.5 --mode pseudocolor --cmap inferno
gif_your_nifti /path/to/mni_icbm152_gm_tal_nlin_asym_09c.nii --size 0.5 --mode pseudocolor --cmap viridis

Changing the size of a gif also changes the frames per second parameter, so that the overall tempo stays the same. Meaning, if you have a gif of original size with 20 frames per second (fps), changing the size to 50%, will cause the smaller gif to run at 10 fps, so that both take the same amount for a cycle.

Use within a python script

You can also use gif_your_nifti from a python script. See script examples for further information.

License

This project is licensed under BSD 3-Clause License.

More Repositories

1

3dprintyourbrain

How to 3D print your brain from a T1 MRI image.
Shell
389
star
2

nipype_tutorial

Learn Nipype with these tutorial notebooks - go here to see them online -->
Jupyter Notebook
120
star
3

atlasreader

Python interface for generating coordinate tables and region labels from statistical MRI images
Jupyter Notebook
88
star
4

fmriflows

fmriflows is a consortium of many (dependent) fMRI analysis pipelines, including anatomical and functional pre-processing, univariate 1st and 2nd-level analysis, as well as multivariate pattern analysis.
MATLAB
60
star
5

workshop_pybrain

Jupyter Notebook
55
star
6

nipype-beginner-s-guide

Beginner's guide for Nipype
Python
37
star
7

parcellation_fragmenter

Fragments FreeSurfer parcellation annotation in N-equal sized parcels
Python
27
star
8

workshop_cambridge

Content for the workshop in Cambridge 2018
Jupyter Notebook
15
star
9

create_fake_fmri_results

Small Notebook to create fake fMRI results (for tutorial or class) - run it online at ->
Jupyter Notebook
6
star
10

noah_ages

Contains the code to create a fun gif in which Noah Kalina ages 20 years in 20 seconds.
Jupyter Notebook
6
star
11

traffic_info_github

Script to track github traffic (views and clones) over period of 14 days
Python
5
star
12

wallpaper_clouded_globe

This script generates a satellite image from the whole planet (with cloud coverage) from https://worldview.earthdata.nasa.gov that than can be used as a wallpaper
Shell
5
star
13

nipype_course

Python
4
star
14

nasa_earthdata

Collect different kinds of satellite images from https://worldview.earthdata.nasa.gov
Jupyter Notebook
4
star
15

LINEViewer

Python based EEG analysis tool that provides a rough data overview
Python
4
star
16

nipype_env

A Docker image for a basic nipype environment
Dockerfile
2
star
17

STEN

Statistical interface for EEG analysing
Python
2
star
18

pac2018

Collection of different approaches to tackle the PAC2018 challenge
Jupyter Notebook
1
star
19

pupillometryAnalyzer

The pupillometryAnalyzer script can be used to analyse pupillometry raw data saved in a wks-file. It analyzes the time-series of one or both eyes and creates informative csv- and png-outputs that can be used for further statistical analysis.
MATLAB
1
star
20

workshop_ino_03

Innovation workshop
Jupyter Notebook
1
star
21

miykael

1
star
22

workshop_mumbai

Content for the workshop in Mumbai 2018
Jupyter Notebook
1
star
23

temporal_binding_window

These matlab scripts compute the temporal binding window (TBW) for a group of subject that participated in a behavioral multisensory integration study
MATLAB
1
star
24

xbar_screentime_tracker

Passive tracking of time spent in front of your screen (optimized for Mac OS X)
Python
1
star