[Neuroimaging] Example code for NiBabel

Gael Varoquaux gael.varoquaux at normalesup.org
Thu Apr 21 14:23:30 EDT 2016


I know that this is probably not the answer that you are looking for, but
in nilearn (which relies on nibabel) it's a couple of lines of code:

from nilearn import image
image.threshold_img('input.nii', threshold=3).to_filename('ouptut.nii')

Reference documentation:



On Thu, Apr 21, 2016 at 04:36:14PM +0000, Simon Rushton wrote:
> Hi All

> I’m new to doing analysis of fmri data using Python and NiBabel.  Could someone
> point me to some very simple code to get me started.  I’m thinking of a program
> just a few lines long that loads a 4D NIfTI file, thresholds each of the
> individual 3D volumes, and then saves the result out as a new 4D NIfTI file. 
> Some simple code like that would get me past all things like accessing data via
> memory pointers etc so I can start learning rather than just scratching my
> head!  And yes, I know that most of this is in the NiBabel documentation but
> I’m obviously not putting the snippets together correctly as my code doesn’t
> work…

> simon

> _______________________________________________
> Neuroimaging mailing list
> Neuroimaging at python.org
> https://mail.python.org/mailman/listinfo/neuroimaging

    Gael Varoquaux
    Researcher, INRIA Parietal
    NeuroSpin/CEA Saclay , Bat 145, 91191 Gif-sur-Yvette France
    Phone:  ++ 33-1-69-08-79-68
    http://gael-varoquaux.info            http://twitter.com/GaelVaroquaux

More information about the Neuroimaging mailing list