0

I have a Nifti file, the size of which is 62*62*38. How can I transfer the Nifti file to .mat Matlab file?

Wolfie
  • 27,562
  • 7
  • 28
  • 55
Angelababy
  • 247
  • 3
  • 7
  • 16
  • Never used Nifti in my life, but google recommends http://www.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image – Mikhail Genkin Mar 16 '15 at 23:28
  • 2
    @MikhailGenkin, why you say "never used Nifti in my life", what are you using in your life now? – Angelababy Mar 16 '15 at 23:48
  • @Angelbaby Is that rhetorical question? Did I say something wrong? Yes, I am not a native speaker and could sometimes speak unclearly. – Mikhail Genkin Mar 16 '15 at 23:51
  • @MikhailGenkin, I understand what you are trying to express. I am just curious why nifti is not popular. – Angelababy Mar 17 '15 at 00:22

3 Answers3

2

Most medical imaging data can be manipulated effectively using some kind of toolbox, such as SPM. However, if you need to gain access to the raw matrix I've always used NIfTI tools from the Mathworks file exchange site (here).

There are two functions that are relevant here: load_nii and load_untouched_nii. The first function load_nii takes care of situations where the header in the NiFTI contains transformations that haven't been applied to the underlying data matrix. If you know that no such transformations exist, you can use load_untouched_nii to avoid the reslicing being done. Both functions return a structure, and the data matrix is located in the img field of the returned structure.

Setsu
  • 1,188
  • 13
  • 26
  • the "img" field generated by "load_untouch_nii() " is int16. How can I change it to "double" class – Angelababy Mar 17 '15 at 20:24
  • 2
    @Angelababy Don't have access to Matlab right now but shouldn't a call to [`double`](http://www.mathworks.com/help/matlab/ref/double.html) solve that? – Setsu Mar 17 '15 at 20:29
  • I already know double(im) solve the problem. Your answer is also good. I do not know how to vote two persons' answer as right answers. Thank you so much! – Angelababy Mar 17 '15 at 22:40
  • 1
    Thanks for your answer, the difference between `load_nii` and `load_untouch_nii` cleared up some confusion I was having. – reas0n May 17 '16 at 21:53
1

This can read NIFTI as well as many other medical image file types into MATLAB arrays, which you can then save as .mat files.

eigenchris
  • 5,791
  • 2
  • 21
  • 30
  • The "volume" class the toolbox generate is "single" , not "double" class. How to transfer to "double" class?? – Angelababy Mar 17 '15 at 20:04
  • @Angelababy If you need to convert the image to double-precision after reading it, you can use `im = double(im);`. – eigenchris Mar 17 '15 at 20:16
0

FreeSurfer has a MATLAB function called "MRIread". It can read NIFTI (.nii, .nii.gz) files into a MATLAB structure, which can then be saved to a MAT file if so desired.

Shanqing Cai
  • 3,756
  • 3
  • 23
  • 36