Skip to content

Instantly share code, notes, and snippets.

@ofgulban
Last active April 28, 2020 17:15
Show Gist options
  • Save ofgulban/2677029103bc2433fcca1c2bf3042711 to your computer and use it in GitHub Desktop.
Save ofgulban/2677029103bc2433fcca1c2bf3042711 to your computer and use it in GitHub Desktop.
Convert nifti to fmr and change the orientations.
% Convert nifti to fmr and change the orientations.
% This scripts requires neuroelf.
%
% NOTES
% -----
% If you are getting erro about `Dyn3DToFMR`:
% 1. Clone the recent neuroelf version from <https://github.com/neuroelf/neuroelf-matlab> (this is written on 2020/04/28).
% 2. Copy `hdr_Dyn3DToFMR.m` file from neuroelf/_todo/@xff/private/ directory and paste in into neuroelf/@xff/private/ directory.
% 3. Comment out the following line fmrc.FirstDataSourceFile = hdrs.F; because otherwise it produces an error.
% 4. Add this modified neuroelf's path to your MATLAB.
%
% This should make the `Dyn3DToFMR` underfied error go away.
clear all; close all;
% Load
nii = xff('/path/to/file.nii');
fmr = nii.Dyn3DToFMR;
data = fmr.Slice.STCData;
% Flip or permute data (change fmr headers if permute)
data = flipdim(data,1);
% save
fmr.Slice.STCData = data;
fmr.SaveAs('/path/to/file_reorient.fmr')
@ortiztudela
Copy link

Hi,
This looks exactly like what I need. However, I get an error when running it:

"mr = nii.Dyn3DToFMR;
Error using xff/subsref (line 202)
Field or method Dyn3DToFMR unknown for type HDR objects."

Is a specific way to call that function? The closest function I have is "hdr_Dyn3DToFMR", but that one also crashes.
Thank you!

@ofgulban
Copy link
Author

Hello @ortiztudelaJ,

For some reason I did not receive any Github notification about this before and saw it now randomly.

What you need to do is to:

  1. clone the recent neuroelf version from here
  2. copy hdr_Dyn3DToFMR.m file from neuroelf/_todo/@xff/private/ directory and paste in into neuroelf/@xff/private/ directory.
  3. Comment out the following line fmrc.FirstDataSourceFile = hdrs.F; because otherwise it produces an error.
  4. Add this modified neuroelf's path to your MATLAB.

Now Dyn3DToFMR method will work.

I will add these instructions as comments in the script. Probably something has changed in the neuroelf over the years and this method became hidden away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment