0001 function vb_job_convert_spm
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 DEBUG = 0;
0046
0047
0048
0049
0050
0051 coord_const = vb_define_coordinate;
0052
0053
0054
0055
0056
0057 if DEBUG==0
0058
0059 try
0060 spm_ver = spm('ver');
0061 catch
0062 error('You can use this function on result display of SPM analysis.');
0063 end
0064 xSPM = get_important_struct(spm_ver);
0065 else
0066 xSPM = [];
0067 end
0068
0069 savefile = [];
0070
0071
0072
0073
0074
0075 mesg = {'Which coordinate is used in the current SPM result?'};
0076 title_txt = 'SPM data import';
0077
0078 ansA = 'Normalised template brain(MNI)';
0079 ansB = 'Subject brain';
0080
0081 STD_sw = questdlg(mesg, title_txt, ansA, ansB, ansA);
0082 switch STD_sw
0083 case ansA
0084 xSPM.coord_type = coord_const.COORDINATE_MNI_RIGHT_MM;
0085 case ansB
0086
0087 imagefile = get_t1_image;
0088 if isempty(imagefile)
0089 disp('T1 image file was not selected.');
0090 return;
0091 end
0092 fprintf('Transform subject native to SPM-right-mm coordinate : ');
0093 fprintf('imagefile %s\n',imagefile);
0094
0095
0096
0097
0098
0099 if DEBUG==0
0100
0101 xSPM = vb_nifti_mm_to_spm_right_mm(xSPM', imagefile)';
0102 xSPM.coord_type = coord_const.COORDINATE_SPM_RIGHT_MM;
0103 end
0104
0105 otherwise
0106 error('Unknown coordinate is specified.');
0107 end
0108
0109
0110
0111
0112
0113 [dir,fnames] = vb_file_select({'.spm.mat'},'Input Save filename(.spm.mat)',true);
0114 if isempty(fnames),
0115 disp('.spm.mat file was not selected.');
0116 return;
0117 end
0118 savefile = [dir filesep fnames{1}];
0119
0120
0121
0122
0123
0124 fprintf('Save file: %s\n',savefile)
0125
0126 if DEBUG==1, return; end
0127
0128 SPM = xSPM;
0129 vb_fsave(savefile,'SPM', 'spm_ver');
0130
0131 return;
0132
0133
0134
0135
0136
0137 function xSPM = get_important_struct(spm_ver)
0138 switch (lower(spm_ver))
0139 case 'spm2'
0140 disp('Check SPM version: SPM2');
0141
0142 command = 'exist(''xSPM'')';
0143 if ~evalin('base',command)
0144 error('Some contrast image must be displayed in SPM.');
0145 else
0146 mSPM = evalin('base','xSPM');
0147 nSPM.Z = mSPM.Z;
0148 nSPM.XYZmm = mSPM.XYZmm;
0149 nSPM.STAT = mSPM.STAT;
0150 xSPM = nSPM;
0151 clear mSPM;
0152 end
0153 clear command;
0154
0155 case 'spm5'
0156 disp('Check SPM version: SPM5');
0157
0158 command = 'exist(''xSPM'')';
0159 if ~evalin('base',command)
0160 error('Some contrast image must be displayed in SPM.');
0161 else
0162 mSPM = evalin('base','xSPM');
0163 nSPM.Z = mSPM.Z;
0164 nSPM.XYZmm = mSPM.XYZmm;
0165 nSPM.STAT = mSPM.STAT;
0166 xSPM = nSPM;
0167 clear mSPM;
0168 end
0169 clear command;
0170
0171 case 'spm8'
0172 disp('Check SPM version: SPM8');
0173
0174 command = 'exist(''xSPM'')';
0175 if ~evalin('base',command)
0176 error('Some contrast image must be displayed in SPM.');
0177 else
0178 mSPM = evalin('base','xSPM');
0179 nSPM.Z = mSPM.Z;
0180 nSPM.XYZmm = mSPM.XYZmm;
0181 nSPM.STAT = mSPM.STAT;
0182 xSPM = nSPM;
0183 clear mSPM;
0184 end
0185 clear command;
0186
0187 otherwise
0188 error('Sorry, this function does not accommodate to your spm version.');
0189 end
0190
0191 function imagefile = get_t1_image
0192 imagefile = '';
0193 [dir,fnames] = vb_file_select({'.hdr','.nii'},'Input T1 image file(.hdr/.nii)');
0194 if ~isempty(fnames)
0195 imagefile = fullfile(dir, fnames{1});
0196 end
0197
0198 function xSPM = backword_transform_normalized_to_subject_native(snfile, spm_ver, xSPM)
0199 switch (lower(spm_ver))
0200 case 'spm2',
0201 sn = load(snfile);
0202 xSPM.XYZmm=vb_unsn(xSPM.XYZmm,sn);
0203
0204 case {'spm5','spm8'},
0205 xSPM.XYZmm = spm_get_orig_coord_spm5((xSPM.XYZmm)',snfile);
0206 xSPM.XYZmm = (xSPM.XYZmm)';
0207 end
0208