RUBY NIFTI


Ruby NIfTI is a pure-ruby library for handling NIfTI data in Ruby. NIfTI (Neuroimaging Informatics Technology Initiative) is an image format designed primarily for storing and analyzing MRI & PET imaging data.

Ruby NIfTI currently only supports basic access to NIfTI files, including
basic and extended header information, as well as image information. There are a ton of good NIfTI libraries and RUBY NIfTI doesn’t try to replace them, but instead we wrote this to provide a decent [we hope] Ruby interface, and allow for easier creation of NIfTI header extensions.

Ruby isn’t seen as a quantitative scripting language yet (Python is more well known, and PyNifti is more mature than NumericalRuby / NArray) so I don’t know how widely this will be used, but you never know.

Installation

gem install nifti

Basic Usage

  1. Initialize the library
    require "nifti"
  2. Read file:
    obj = NIFTI::NObject.new("some_file.nii")
  3. Display some key information about the file:
    puts obj.header['sform_code_descr']
    => "NIFTI_XFORM_SCANNER_ANAT"
  4. Retrieve the pixel data in a Ruby Array:
    image = obj.get_image
  5. Load the pixel data to an NArray image object and display it on the screen:
    image = obj.get_image_narray

Resources

Credit

Ruby NIfTI is highly derivative of the very good Ruby DICOM library, from which all of the design and most of the code has been cold-heartedly stolen. Many thanks to Chris Lervag – this wouldn’t exist without his examples.

Author: Erik Kastman