12
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Expecting the answer ^^; +1 $\endgroup$ – Sektor Aug 27 '15 at 12:52
  • 2
    $\begingroup$ @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. $\endgroup$ – Szabolcs Aug 27 '15 at 12:57
  • 1
    $\begingroup$ 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. $\endgroup$ – Szabolcs Aug 27 '15 at 13:17
12
$\begingroup$

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.
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Nicolas Boutry Apr 27 at 2:18
  • 1
    $\begingroup$ @NicolasBoutry I don't know, I no longer work with MRI nifti files. You could try this newer package: github.com/mfroeling/QMRITools $\endgroup$ – Szabolcs Apr 27 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.