source: misclib/fmri_spm_volumes.m @ 188

Last change on this file since 188 was 129, checked in by tjniskan, 9 years ago
  • Added plugin for correlation mapping with filtering/other options
  • Added flipping of 3D ROIs in aedes.m
  • Added possibility of changing ROI color (in the ROI -uimenu)
  • Minor fixes/changes here and there...

M misclib/fmri_spm_volumes.m
M misclib/fmri_filter.m
M aedes_fitmaps.m
M aedes.m
M plugins/save_roi_as_mask.m
M plugins/calc_asl_cbf.m
A plugins/fmri_plugins/correlation_mapping.m
M plugins/fmri_plugins/resting_state_fc.m
M plugins/map_plugins/t1_inversion_recovery.m
M aedes_revision.m

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

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