Code Monkey home page Code Monkey logo

gif_your_nifti's Introduction

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

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

pip install -r requirements.txt
python setup.py install

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.

gif_your_nifti's People

Contributors

ilkayisik avatar masadcv avatar miykael avatar octomike avatar ofgulban avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.