# Reading NIfTI-1 files

How can I read NIfTI-1 files (.nii extension) in Mathematica? Are there existing tools for this?

• Expecting the answer ^^; +1 – Sektor Aug 27 '15 at 12:52
• @Sektor Sorry, no answer yet. I'm looking at Neurotica but it doesn't handle my files. I might end up doing it from scratch. Either way, I thought it would be a good idea to have a question on this. – Szabolcs Aug 27 '15 at 12:57
• Well, I was wrong, it does read my files correctly. This looks to be a large package with some very complete bits. Implementing the NifTI importer must have taken quite a bit of time. – Szabolcs Aug 27 '15 at 13:17

The Neurotica package by Noah Benson has support for importing NifTI files. It registers the "NIFTI" import format, to make importing as convenient as Import["somefile.nii", "NIFTI"].

However, by default this returns an MRImage3D object, which is specific to the Neurotica package and doesn't support arbitrary dimensional data. If the data is high dimensional, the import attempt might result in an error. The fix is to use

Import["somefile.nii", {"NIFTI", "Voxels"}]


instead, which only imports the raw data, without additional processing.

There are four import elements:

• "Header" gives the metadata in the header as a rule list.
• "Metainformation" is the same as the above, but the output is in the {"Header" -> ...} format.
• "Data" gives {"Header" -> ..., "Voxels" -> ...}
• "Voxels" gives the raw data from the file as a multidimensional packed array.
• I have some troubles to import Nifti files with the instructions above: Import["Brats18_CBICA_AAB_1/Brats18_CBICA_AAB_1_flair.nii", "NIFTI"]; It returns me an error: ![enter image description here](i.stack.imgur.com/yc2S9.png) Did someone got this error? Is there a way to solve this problem? What is strange is that it works well with the 30 first images of my folder of 285 brains ... Thanks for your help, N.B. – Nicolas Boutry Apr 27 '19 at 2:18
• @NicolasBoutry I don't know, I no longer work with MRI nifti files. You could try this newer package: github.com/mfroeling/QMRITools – Szabolcs Apr 27 '19 at 8:37