source: misclib/fmri_spm_volumes.m @ 64

Last change on this file since 64 was 62, checked in by tjniskan, 11 years ago
  • Added functions for basic fMRI analysis and resting-state
  • Added trend in the "show voxel timeseries" figure. In EPI datas the

the reference image is excluded from the time series and the y-axis
units are changed to "BOLD (%)".

  • Fixed an endiannes bug in an2_readfdf.m
  • Added plugins basic fmri analysis and resting-state analysis

M misclib/fmri_spm_volumes.m
A misclib/fmri_analysis.m
M an2_readfdf.m
M an2_revision.m
M an2_fitmaps.m
M an2_data_read.m
M aedes.m
A plugins/basic_fmri_analysis.m
A plugins/resting_state_fc.m

File size: 2.6 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
81else
82  error('No PROCPAR found!')
83end
84
85if isEPI
86  % Remove first slice from EPI data
87  data.FTDATA = data.FTDATA(:,:,:,2:end);
88end
89
90if isempty(StartVolume)
91  StartVolume = 1;
92end
93
94if isempty(EndVolume)
95  EndVolume = size(data.FTDATA,4);
96end
97
98nVols = length(StartVolume:EndVolume);
99
100wbh = an2_wbar(0,['Writing volumes...']);
101
102% Write output images
103count=0;
104for ii=StartVolume:EndVolume
105  count=count+1;
106 
107  an2_wbar(count/nVols,wbh,'Writing volumes...');
108 
109  % Check if volume should be omitted
110  if ~isempty(OmitVolumes) && any(ii==OmitVolumes)
111    continue
112  end
113 
114  % Get volume
115  vol = data.FTDATA(:,:,:,ii);
116 
117  % Rotate and flip volumes VNMR EPI and RASER to right orientations
118  if isEPI
119    vol = flipdim(an2_rot3d(vol,1,3),2);
120  elseif isRASER
121    vol = flipdim(vol,2);
122  end
123 
124  % Construct file name
125  fname = sprintf('%s_%04d.nii',filename,ii);
126 
127  % Write the NIfTI file
128  done=an2_write_nifti(vol,[outdir,fname],...
129    'VoxelSize',VoxelSize,...
130    'XYZUnits',XYZUnits,...
131    'TimeUnits',TimeUnits);
132  if ~done
133    error('Could not write file')
134  end
135end
136close(wbh)
137
138
139
140
141
142
143 
Note: See TracBrowser for help on using the repository browser.

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