source: misclib/fmri_spm_volumes.m @ 61

Last change on this file since 61 was 61, checked in by tjniskan, 11 years ago
  • Added a function for making NIfTI volumes for SPM
  • Added cluster size thresholding in fmri_blob_overlay.m

A misclib/fmri_spm_volumes.m
M misclib/fmri_blob_overlay.m
M an2_revision.m

File size: 2.5 KB
Line 
1function fmri_spm_volumes(infile,outdir,varargin)
2%
3%
4%
5
6if nargin<2
7  error('Too few input arguments')
8end
9
10if ~isdir(outdir)
11  error('The output folder %s does not exist!',outdir)
12end
13
14% Defaults
15[fp,fn,fe] = fileparts(infile);
16if strcmpi(fn,'fid')
17  [fp,fn,fe] = fileparts(fp);
18  filename = fn;
19else
20  filename = fn;
21end
22VoxelSize = [1 1 1.5 2.039];
23XYZUnits = 'mm';
24TimeUnits = 'sec';
25OmitVolumes = [];
26StartVolume = [];
27EndVolume = [];
28
29% Parse varargin
30if rem(length(varargin),2)~=0
31  error('Invalid property/value pairs!')
32end
33
34for ii=1:2:length(varargin)
35  prop = varargin{ii};
36  value = varargin{ii+1};
37 
38  switch lower(prop)
39    case 'filename'
40      filename = value;
41    case 'voxelsize'
42      VoxelSize = value;
43    case 'xyzunits'
44      XYZUnits = value;
45    case 'timeunits'
46      TimeUnits = value;
47    case 'omitvolumes'
48      OmitVolumes = value;
49    case 'startvolume'
50      StartVolume = value;
51    case 'endvolume'
52      EndVolume = value;
53    otherwise
54      error('Unknown property %s',prop)
55  end
56end
57
58% Check that outdir contains the final file separator
59if ~strcmp(outdir(end),filesep)
60  outdir = [outdir,filesep];
61end
62
63
64% Read the fMRI data
65data = an2_readfid(infile,'FastRead','on');
66if isempty(data)
67  disp('FMRI_SPM_VOLUMES: Action canceled...')
68  return
69end
70
71% Check if is EPI or RASER data
72isEPI = false;
73isRASER = false;
74if isfield(data,'PROCPAR')
75  if isfield(data.PROCPAR,'phaseres') && ...
76      isfield(data.PROCPAR,'readres')
77    isEPI = true;
78  elseif isfield(data.PROCPAR,'teType')
79    isRASER = true
80  end
81end
82
83if isEPI
84  % Remove first slice from EPI data
85  data.FTDATA = data.FTDATA(:,:,:,2:end);
86end
87
88if isempty(StartVolume)
89  StartVolume = 1;
90end
91
92if isempty(EndVolume)
93  EndVolume = size(data.FTDATA,4);
94end
95
96nVols = length(StartVolume:EndVolume);
97
98wbh = an2_wbar(0,['Writing volumes...']);
99
100% Write output images
101for ii=StartVolume:EndVolume
102 
103  an2_wbar(ii/nVols,wbh,'Writing volumes...');
104 
105  % Check if volume should be omitted
106  if ~isempty(OmitVolumes) && any(ii==OmitVolumes)
107    continue
108  end
109 
110  % Get volume
111  vol = data.FTDATA(:,:,:,ii);
112 
113  % Rotate and flip volumes VNMR EPI and RASER to right orientations
114  if isEPI
115    vol = flipdim(an2_rot3d(vol,1,3),2);
116  elseif isRASER
117    vol = flipdim(vol,2);
118  end
119 
120  % Construct file name
121  fname = sprintf('%s_%04d.nii',filename,ii);
122 
123  % Write the NIfTI file
124  done=an2_write_nifti(vol,[outdir,fname],...
125    'VoxelSize',VoxelSize,...
126    'XYZUnits',XYZUnits,...
127    'TimeUnits',TimeUnits);
128  if ~done
129    error('Could not write file')
130  end
131end
132close(wbh)
133
134
135
136
137
138
139 
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008