0001 function [phiw, msgstr] = phiw_options(optstr, phiw, cfg_fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if nargin < 1
0026 optstr = 'load';
0027 end
0028 if nargin < 2
0029 phiw = [];
0030 end
0031 if nargin < 3
0032 cfg_fname = '';
0033 end
0034 if isempty(phiw)
0035 phiw = mars_struct('getifthere', spm('getglobal','PHI'), 'OPTIONS');
0036 end
0037 msgstr = '';
0038
0039
0040 optfields = {'wt','denoise','structural','display','statistics'};
0041 optlabs = {'Wavelet transform','Denoising','Default structural', ...
0042 'Image display','Statistics'};
0043
0044 switch lower(optstr)
0045
0046
0047 case 'load'
0048 if isempty(cfg_fname)
0049 [fn, fn2] = phiwave('cfgfile');
0050 if isempty(fn), fn=fn2;end
0051 [p f e] = fileparts(fn);
0052 cfg_fname = spm_get([0 1],[f e], 'Configuration file to load',p);
0053 end
0054 if ~isempty(cfg_fname)
0055 tmp = load(cfg_fname);
0056 if ~isempty(tmp)
0057 if isfield(tmp, 'phiw')
0058 phiw = mars_struct('fillafromb', tmp.phiw, phiw);
0059 end
0060 end
0061 end
0062
0063
0064 case 'save'
0065 if nargin < 3
0066 [fn, fn2] = phiwave('cfgfile');
0067 if isempty(fn), fn=fn2;end
0068 [f p] = uiputfile(fn, 'Configuration file to save');
0069 cfg_fname = fullfile(p, f);
0070 end
0071 if ~isempty(cfg_fname)
0072 try
0073 save(cfg_fname, 'phiw');
0074 catch
0075 warning(['Error saving config to file ' cfg_fname])
0076 end
0077 end
0078
0079
0080 case 'basedefaults'
0081
0082
0083
0084 phiw.wt.scales = 4;
0085
0086
0087 phiw.wt.wavelet = phiw_lemarie(2);
0088
0089
0090 phiw.wt.wtprefix = 'wv_';
0091
0092
0093 phiw.statistics.maskthresh = 0.05;
0094
0095
0096 phiw.statistics.write_res = 1;
0097
0098
0099 phiw.denoise.thlev = 'quadrant';
0100
0101
0102 phiw.denoise.thcalc = 'stein';
0103
0104
0105 phiw.denoise.thapp = 'linear';
0106
0107
0108 phiw.denoise.ncalc = 'n';
0109
0110
0111 phiw.denoise.alpha = 0.05;
0112
0113
0114 phiw.denoise.write_err = 0;
0115
0116
0117 phiw.structural.fname = fullfile(spm('Dir'), 'canonical', ...
0118 ['avg152T1' mars_veropts('template_ext')]);
0119
0120
0121 phiw.structural.range = [];
0122
0123
0124 phiw.display.cmapname = 'flow.lut';
0125
0126
0127 phiw.display.actprop = 0.5;
0128
0129
0130 phiw.display.transform = 'axial';
0131
0132
0133 phiw.display.slices = -60:6:78;
0134
0135
0136 case 'edit'
0137
0138
0139 defarea = cfg_fname;
0140 if isempty(defarea)
0141
0142 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Phiwave Defaults');
0143
0144 optfields = {'wt','statistics', 'denoise','structural','display'};
0145 optlabs = {'Wavelet transform', 'Statistics', 'Denoising', ...
0146 'Default structural', 'Image display'};
0147
0148 defarea = char(...
0149 spm_input('Defaults area', '+1', 'm',{optlabs{:} 'Quit'},...
0150 {optfields{:} 'quit'},length(optfields)+1));
0151 end
0152
0153 oldphiw = phiw;
0154 switch defarea
0155 case 'quit'
0156 return
0157 case 'wt'
0158
0159 phiw.wt.scales = spm_input('Scales for analysis', ...
0160 '+1', 'e', phiw.wt.scales, ...
0161 1);
0162
0163
0164 wlabs = {'Battle-Lemarie', 'Daubechies'};
0165 wtypes = {'phiw_lemarie', 'phiw_daub'};
0166 tmp = oldphiw.wt;
0167 tmp.wavelet = class(tmp.wavelet);
0168 phiw.wt = getdefs(...
0169 phiw.wt,...
0170 tmp,...
0171 'wavelet',...
0172 'Wavelet',...
0173 wtypes,...
0174 wlabs);
0175 switch phiw.wt.wavelet
0176 case 'phiw_lemarie'
0177 wv = phiw_lemarie;
0178 d_d = spm_input('Divisor for image width', '+1', 'e', 2);
0179 wv = dim_div(wv, d_d);
0180 case 'phiw_daub'
0181 wv = phiw_daub;
0182 n_c = spm_input('Number of coefficients', '+1', 'e', 4);
0183 wv = num_coeffs(wv, n_c);
0184 end
0185 phiw.wt.wavelet = wv;
0186
0187
0188 phiw.wt.wtprefix = spm_input('WT image prefix', '+1', 's', ...
0189 phiw.wt.wtprefix);
0190
0191
0192
0193 case 'statistics'
0194
0195
0196
0197 phiw.statistics.maskthresh = spm_input('Threshold for WT brain mask', '+1', ...
0198 'e', ...
0199 phiw.statistics.maskthresh, ...
0200 1);
0201
0202
0203
0204 phiw.statistics.write_res = spm_input('Write residual images?', '+1', ...
0205 'b', 'Yes|No', [1 0], ...
0206 2 - phiw.statistics.write_res*-1);
0207
0208 case 'denoise'
0209
0210
0211
0212 phiw.denoise = getdefs(...
0213 phiw.denoise,...
0214 oldphiw.denoise,...
0215 'thcalc',...
0216 'Threshold calculation',...
0217 {'visu','sure','stein','bonf','fdr','hoch'},...
0218 ['MinMax|SURE|Stein|Bonferroni|FDR|Hoch']); ...
0219
0220
0221 phiw.denoise = getdefs(...
0222 phiw.denoise,...
0223 oldphiw.denoise,...
0224 'thlev',...
0225 'Threshold level',...
0226 {'image','level','quadrant'},...
0227 ['Image|Level|Quadrant']);
0228
0229
0230
0231 if strmatch('sure', phiw.denoise.thcalc)
0232 phiw.denoise.thapp = 'soft';
0233 else
0234 vals = {'soft','hard'};
0235 labs = 'Soft|Hard';
0236 if strcmp(phiw.denoise.thcalc, 'stein')
0237 vals = {vals{:},'linear'};
0238 labs = [labs '|Linear'];
0239 end
0240 phiw.denoise = getdefs(...
0241 phiw.denoise,...
0242 oldphiw.denoise,...
0243 'thapp',...
0244 'Thresholding method',...
0245 vals,...
0246 labs);
0247 end
0248
0249
0250 if any(strcmp(phiw.denoise.thcalc,...
0251 {'bonf','hoch','fdr'}))
0252
0253
0254 phiw.denoise = getdefs(...
0255 phiw.denoise,...
0256 oldphiw.denoise,...
0257 'ncalc',...
0258 'Estimate of Ho coefficient no',...
0259 {'n','pplot'},...
0260 ['Raw no|PPlot']);
0261
0262
0263 phiw.denoise.alpha = spm_input('Alpha level', '+1', 'r', ...
0264 phiw.denoise.alpha,1,[0 1]);
0265 else
0266 phiw.denoise.ncalc = 'n';
0267 end
0268
0269
0270 phiw.denoise.write_err = spm_input('Write denoised variance?', '+1', ...
0271 'b', 'Yes|No', [1 0], ...
0272 2 - phiw.denoise.write_err*-1);
0273
0274
0275 case 'structural'
0276 phiw.structural.fname = spm_get(1, mars_veropts('get_img_ext'),...
0277 'Default structural image', ...
0278 fileparts(phiw.structural.fname));
0279
0280
0281 [mx mn] = slover('volmaxmin', spm_vol(phiw.structural.fname));
0282 phiw.structural.range = spm_input('Img range for structural','+1', ...
0283 'e', [mn mx], 2);
0284
0285
0286 case 'display'
0287
0288 cmap = [];
0289 ypos = spm_input('!NextPos');
0290 while isempty(cmap)
0291 cmapname = spm_input('Name of activation colormap', ypos,'s', ...
0292 phiw.display.cmapname);
0293 [cmap str] = slover('getcmap', cmapname);
0294 if isempty(cmap)
0295 disp(str);
0296 end
0297 end
0298 phiw.display.cmapname = cmapname;
0299
0300
0301 phiw.display.actprop = spm_input('Activation colour intensity', '+1', 'r', ...
0302 phiw.display.actprop,1,[0 1]);
0303
0304 phiw.display.transform = lower(spm_input('Image orientation', '+1','b',...
0305 ['Axial|Coronal|Sagittal'], [],1));
0306 ypos = spm_input('!NextPos'); sflg = 0;
0307 while ~sflg
0308 sflg=1;
0309 slstr = spm_input('Slices to display (mm)', ypos, 's', ...
0310 sprintf('%0.0f:%0.0f:%0.0f',...
0311 min(phiw.display.slices),...
0312 mean(diff(phiw.display.slices)),...
0313 max(phiw.display.slices)));
0314 eval(['phiw.display.slices = ' slstr ';'], 'sflg=0;');
0315 end
0316
0317
0318 case 'statistics'
0319 phiw.statistics.maskthresh = spm_input('WT mask threshold', '+1', 'r', ...
0320 phiw.statistics.maskthresh,1,[0 1]);
0321
0322 otherwise
0323 error('Unknown defaults area')
0324 end
0325
0326
0327 if spm_input('Accept these settings', '+1', 'b','Yes|No',[0 1],1)
0328 phiw = oldphiw;
0329 end
0330
0331
0332 case 'defaults'
0333 pwdefs = [];
0334 msgstr = 'base defaults';
0335 cfgfile = phiwave('cfgfile');
0336 if ~isempty(cfgfile);
0337 tmp = load(cfgfile);
0338 if isfield(tmp, 'phiw')
0339 pwdefs = tmp.phiw;
0340 msgstr = cfgfile;
0341 else
0342 warning(...
0343 ['File ' cfgfile ' does not contain valid config settings'],...
0344 'Did not load phiwave config file');
0345 end
0346 end
0347 phiw = mars_struct('fillafromb', ...
0348 pwdefs, phiw_options('basedefaults'));
0349
0350
0351 case 'fill'
0352 phiw = mars_struct('fillafromb', phiw, cfg_fname);
0353
0354 otherwise
0355 error('Don''t recognize options action string')
0356 end
0357 return
0358
0359
0360
0361
0362
0363 function s = getdefs(s, defval, fieldn, prompt, vals, labels)
0364
0365
0366 if isstruct(defval)
0367 defval = getfield(defval, fieldn);
0368 end
0369
0370 if ischar(defval)
0371 defind = find(strcmp(defval,vals));
0372 else
0373 defind = find(defval == vals);
0374 end
0375
0376 v = spm_input(prompt, '+1', 'm', labels, vals, defind);
0377 if iscell(v) & ischar(defval)
0378 v = char(v);
0379 end
0380
0381 s = setfield(s,fieldn,v);
0382
0383 return