forked from spunt/bspmview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbspmview.m
7604 lines (7100 loc) · 292 KB
/
bspmview.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = bspmview(ol, ul)
% BSPMVIEW Program for viewing fMRI statistical maps
%
% USAGE: varargout = bspmview(ol*, ul*) *optional inputs
%
% Requires that Statistical Parametric Mapping (SPM; Wellcome Trust Centre for
% Neuroimaging; www.fil.ion.ucl.ac.uk/spm/) be in your MATLAB search path. In
% addition, it requires a number of supporting utility functions and data
% files that should have been included in the distribution of BSPMVIEW. When
% BSPMVIEW is launched, it will look for these files in a folder called
% "supportfiles" that should be contained in the same folder as this function.
% It has been tested on SPM8/SPM12 operating in MATLAB 2014b running in both
% Windows 8.1 and OS X Yosemite.
%
% ________________________________________________________________________________
% COMMAND LINE USAGE
% ________________________________________________________________________________
%
% INPUTS
% ol: filename for statistical image to overlay
% ul: filename for anatomical image to use as underlay
%
% EXAMPLES
% bspmview('spmT_0001.img', 'T1.nii') % overlay on 'T1.nii'
% bspmview('spmT_0001.nii.gz') % overlay on default underlay
% bspmview % open dialogue for selecting overlay
% S = bspmview; % returns struct 'S' w/graphics handles
%
% ________________________________________________________________________________
% ACKNOWLEDGMENTS
% ________________________________________________________________________________
%
% This software heavily relies on functionality contained within SPM and is in
% many ways an attempt to translate it into a simpler and more user-friendly
% interface. Special thanks goes to Jared Torre for testing an early version
% of the code, and to Guillaume Flandin for help with adding BSPMVIEW to the
% SPM Extensions webpage. In addition, this software was initially inspired by
% and in some cases adapts code from two other statistical image viewers:
% - XJVIEW by Xu Cui, Jian Li, & Xiaowei Song (alivelearn.net/xjview8)
% - FIVE by Aaron P. Schultz (mrtools.mgh.harvard.edu)
%
% Moreover, numerous other open-source MATLAB fMRI analysis tools provided the
% raw material for many of the functions included in BSPMVIEW, including:
% - SURFPLOT (mrtools.mgh.harvard.edu/index.php/SurfPlot)
% - PEAK_NII (nitrc.org/projects/peak_nii)
% - Anatomy Toolbox (fil.ion.ucl.ac.uk/spm/ext/#Anatomy)
% - Anatomical Automatic Labeling 2 (AAL2) (http://www.gin.cnrs.fr/AAL2)
% - Harvard-Oxford Atlas (from FSL) (http://cma.mgh.harvard.edu/fsl_atlas.html)
%
% Finally, several contributions to the MATLAB File Exchange
% (mathworks.com/matlabcentral/fileexchange/) are called by the code. These
% are included in the "supporting files" folder included in the distribution
% of BSPMVIEW. The documentation of the supporting functions contains further
% information about the source and respective copyright holders.
%
% ------ Copyright (C) Bob Spunt, California Institute of Technology ------
% Email: [email protected]
% Created: 2014-09-27
% GitHub: https://github.com/spunt/bspmview
% Version: 20170411
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or (at
% your option) any later version.
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see: http://www.gnu.org/licenses/.
% _________________________________________________________________________
global bspmview_version
bspmview_version='20170411';
% | CHECK FOR SPM FOLDER
% | =======================================================================
spmdir = fileparts(which('spm'));
if isempty(spmdir)
printmsg('SPM could not be found on your path. Add it and try again.', 'ERROR'); return;
else
addpath(fullfile(spmdir,'matlabbatch'));
addpath(fullfile(spmdir,'config'));
end
% | CHECK FOR SUPPORTFILES, USERPREF, AND SPM FOLDER
% | =======================================================================
mfilepath = fileparts(mfilename('fullpath'));
supportdir = fullfile(mfilepath, 'supportfiles');
if ~exist(supportdir, 'dir'), printmsg('The folder "supportfiles" was not found', 'ERROR'); return; end
addpath(supportdir);
% | CHECK INPUTS
% | =======================================================================
if nargin < 1
% | CHECK FOR OPEN SPM
hcon = findobj(0, 'Name', 'SPM contrast manager');
if ~isempty(hcon)
huserdata = get(hcon, 'UserData');
selectdir = huserdata.swd;
else
selectdir = pwd;
end
ol = uigetvol('Select an Image File for Overlay', 0, selectdir);
if isempty(ol), disp('Must select an overlay!'); return; end
else
if all([~ischar(ol) ~iscell(ol)]), disp('First argument must be a string or cell array!'); return; end
if strcmpi(ol, 'TEST')
tmp{1} = fullfile(supportdir, 'test_overlay', 'spmT_0001.nii');
tmp{2} = fullfile(supportdir, 'test_overlay', 'spmT_0001.nii.gz');
if any(cellfun(@exist, tmp)), ol = tmp{find(cellfun(@exist, tmp))};
else disp('Overlay image file cannot be found!'); return; end
end
if iscell(ol), ol = char(ol); end
end
if nargin < 2
ul = fullfile(supportdir, 'IIT_MeanT1_2x2x2.nii');
else
if all([~ischar(ul) ~iscell(ul)]), disp('Second argument must be a string or cell array!'); return; end
if iscell(ul), ul = char(ul); end
if ~exist(ul, 'file'), disp('Underlay image file cannot be found!'); return; end
end
% | DEFAULTS
% | =======================================================================
global prevsect st
prevsect = ul;
st.guipath = mfilepath;
st.supportpath = supportdir;
st.fonts = default_fonts;
st.pos = default_positions;
preffile = fullfile(getenv('HOME'), 'bspmview_preferences.mat');
if exist(preffile, 'file')
st.preferences = load(preffile);
else
st.preferences = default_settings;
end
put_startupmsg;
% | INITIALIZE FIGURE, SPM REGISTRY, & ORTHVIEWS
% | =======================================================================
try
S = put_figure(ol, ul); shg;
if nargout, varargout = {S}; end
catch err
save_error(err);
rethrow(err)
end
% =========================================================================
% *
% * SUBFUNCTIONS
% *
% =========================================================================
% | GUI DEFAULTS
% =========================================================================
function def = default_settings
def = struct( ...
'atlasname' , 'AnatomyToolbox' , ...
'alphacorrect' , .05 , ...
'separation' , 20 , ...
'numpeaks' , 3 , ...
'alphauncorrect', .001 , ...
'clusterextent' , 5 , ...
'surfshow' , 4 , ...
'surface' , 'Inflated' , ...
'shading' , 'Sulc' , ...
'nverts' , 40962 , ...
'round' , false , ...
'neighbor' , 0 , ...
'dilate' , false , ...
'shadingmin' , .15 , ...
'shadingmax' , .70 , ...
'colorbar' , true ...
);
function prefs = default_preferences(initial)
if nargin < 1, initial = 0; end
global st
deffile = fullfile(getenv('HOME'), 'bspmview_preferences.mat');
st.preferences = catstruct(default_settings, st.preferences);
def = st.preferences;
if initial
try
save(deffile, '-struct', 'def');
return;
catch err
printmsg('Error saving user preferences to disk. Using defaults...', 'WARNING');
disp(err.message);
return
end
end
pos = get(st.fig, 'pos');
w = pos(3)*.65;
opt = {'L/R Medial/Lateral' 'L/R Lateral' 'L Medial/Lateral' 'R Medial/Lateral' 'L Lateral' 'R Lateral'};
optmap = [4 2 1.9 2.1 -1 1];
opt = [opt(optmap==def.surfshow) opt(optmap~=def.surfshow)];
optmap = [optmap(optmap==def.surfshow) optmap(optmap~=def.surfshow)];
surftypeopt = {'Inflated' 'Pial' 'White' 'PI'};
surftypeopt = [surftypeopt(strcmpi(surftypeopt, def.surface)) surftypeopt(~strcmpi(surftypeopt, def.surface))];
surftypeshade = {'Sulc' 'Curv' 'Thk' 'LogCurv' 'Mixed'};
surftypeshade = [surftypeshade(strcmpi(surftypeshade, def.shading)) surftypeshade(~strcmpi(surftypeshade, def.shading))];
nvertopt = [40962 642 2562 10242 163842];
nvertopt = [nvertopt(nvertopt==def.nverts) nvertopt(nvertopt~=def.nverts)];
atlasopt = { ...
'AAL2' ,...
'HarvardOxford-maxprob-thr0' ,...
'HarvardOxford-cort-maxprob-thr0' ,...
'HarvardOxford-sub-maxprob-thr0' ,...
'AnatomyToolbox' ...
};
atlasopt = [atlasopt(strcmpi(atlasopt, def.atlasname)) atlasopt(~strcmpi(atlasopt, def.atlasname))];
[prefs, button] = settingsdlg('title', 'Settings', 'WindowWidth', w, 'ControlWidth', w/2, ...
'separator' , 'Thresholding', ...
{'Default P-Value (Uncorrected)'; 'alphauncorrect'} , def.alphauncorrect, ...
{'Default Extent'; 'clusterextent'} , def.clusterextent, ...
{'Voxelwise FWE'; 'alphacorrect'} , def.alphacorrect, ...
{'Peak Separation'; 'separation'} , def.separation, ...
{'# Peaks/Cluster'; 'numpeaks'} , def.numpeaks, ...
'separator' , 'Anatomical Labeling', ...
{'Name'; 'atlasname'} , atlasopt, ...
'separator' , 'Surface Rendering', ...
{'Surfaces to Render'; 'surfshow'} , opt, ...
{'Surface Type'; 'surface'} , surftypeopt, ...
{'Shading Type'; 'shading'} , surftypeshade, ...
{'N Vertices'; 'nverts'} , num2cell(nvertopt), ...
{'Shading Min'; 'shadingmin'} , def.shadingmin, ...
{'Shading Max'; 'shadingmax'} , def.shadingmax, ...
{'Add Color Bar?'; 'colorbar'} , logical(def.colorbar), ...
{'Dilate Inclusive Mask?'; 'dilate'} , logical(def.dilate), ...
{'Round Values? (binary images)'; 'round'} , logical(def.round), ...
{'Nearest Neighbor? (binary/label images)'; 'neighbor'}, logical(def.neighbor));
if strcmpi(button, 'cancel')
return
else
st.preferences = prefs;
end
if ~strcmpi(st.preferences.atlasname, def.atlasname)
setatlas;
setregionname;
end
st.preferences.surfshow = optmap(strcmpi(opt, st.preferences.surfshow));
def = st.preferences;
try
save(deffile, '-struct', 'def');
return;
catch err
printmsg('Error saving user preferences to disk. Using defaults...', 'WARNING');
disp(err.message);
return;
end
function pos = default_positions
screensize = get(0, 'ScreenSize');
pos.ss = screensize(3:4);
pos.gui = [pos.ss(1)*.20 25 pos.ss(2)*.55 pos.ss(2)*.50];
pos.gui(3:4) = pos.gui(3:4)*1.10;
pos.aspratio = pos.gui(3)/pos.gui(4);
if pos.gui(3) < 550
pos.gui(3) = 550;
pos.gui(4) = pos.gui(3)*pos.aspratio;
end
if sum(pos.gui([2 4])) > (pos.ss(2)*.95)
pos.gui(4) = pos.ss(2)*.90 - 25;
pos.gui(3) = pos.gui(4)/pos.aspratio;
end
guiss = [pos.gui(3:4) pos.gui(3:4)];
panepos = getpositions(1, [17 1], .01, .01);
pos.pane.upper = panepos(2,3:end);
pos.pane.axes = panepos(1,3:end).*guiss;
function color = default_colors(darktag)
if nargin==0, darktag = 1; end
if darktag
color.fg = [248/255 248/255 248/255];
color.bg = [20/255 23/255 24/255] * 2;
color.border = [023/255 024/255 020/255]*2;
color.panel = [.01 .22 .34];
color.edit = [.95 .95 .95];
color.font = [0 0 0];
else
color.fg = [20/255 23/255 24/255];
color.bg = [248/255 248/255 248/255] * .95;
color.edit = [.95 .95 .95];
color.border = 1 - ([023/255 024/255 020/255]*2);
color.edit = [.95 .95 .95];
color.font = [0 0 0];
end
color.xhair = [0.7020 0.8039 0.8902];
color.blues = brewermap(40, 'Blues');
function fonts = default_fonts
% | Font Size
if regexpi(computer, '^PCWIN')
PROP = 1/150;
else
PROP = 1/110;
end
SS = get(0, 'screensize');
sz1 = round(SS(3)*PROP);
sz2 = round(sz1*(3/4));
sz3 = round(sz1*(2/3));
sz4 = round(sz1*(3/5));
sz5 = round(sz1*(5/9));
sz6 = round(sz1*(1/2));
sz = [sz1 sz2 sz3 sz4 sz5 sz6];
if sz6 < 10
sz = [sz1 sz2 sz3 sz4 sz5 sz6];
sz = ceil(scaledata(sz, [10 sz1]));
elseif sz1 > 24
sz = [sz1 sz2 sz3 sz4 sz5 sz6];
sz = ceil(scaledata(sz, [sz6 24]));
end
fonts.sz1 = sz(1);
fonts.sz2 = sz(2);
fonts.sz3 = sz(3);
fonts.sz4 = sz(4);
fonts.sz5 = sz(5);
fonts.sz6 = sz(6);
% | Font Name
fonts.name = 'Helvetica';
function prop = default_properties(varargin)
global st
prop.darkbg = {'backg', st.color.bg, 'foreg', st.color.fg};
prop.lightbg = {'backg', st.color.fg, 'foreg', [0 0 0]};
if ~isempty(varargin), prop.darkbg = [varargin{:} prop.darkbg]; prop.lightbg = [varargin{:} prop.lightbg]; end
prop.panel = [prop.darkbg {'bordertype', 'none', 'titlepos', 'centertop', 'fontw', 'bold'}];
prop.edit = [prop.lightbg {'style', 'edit', 'horiz', 'center'}];
prop.text = [prop.darkbg {'style', 'text', 'horiz', 'center'}];
prop.popup = [prop.lightbg {'style', 'popup'}];
prop.push = [prop.darkbg {'style', 'push', 'horiz', 'center'}];
prop.radio = [prop.darkbg {'style', 'radio', 'horiz', 'center'}];
prop.toggle = [prop.darkbg {'style', 'toggle'}];
prop.checkbox = [prop.darkbg {'style', 'check'}];
prop.listbox = [prop.darkbg {'style', 'list'}];
function cmap = default_colormaps(depth)
if nargin==0, depth = 64; end
cmap = [];
cmap{1,1} = [];
cmap{1,2} = 'signed';
cmap{2,1} = hot(depth);
cmap{2,2} = 'hot';
cmap{3,1} = cold(depth);
cmap{3,2} = 'cold';
cmap{4,1} = jet(depth);
cmap{4,2} = 'jet';
cmap{5,1} = [];
cmap{5,2} = 'cubehelix';
cmap{6,1} = [];
cmap{6,2} = 'linspecer';
cmap{7,1} = colorGray(depth);
cmap{7,2} = 'colorGray';
anchor = size(cmap,1);
bmap1 = {'Blues' 'Greens' 'Greys' 'Oranges' 'Purples' 'Reds'};
for i = 1:length(bmap1)
tmp = brewermap(50, bmap1{i});
cmap{anchor+i,1} = cmap_upsample(tmp(11:end,:), depth);
cmap{anchor+i,2} = sprintf('%s', bmap1{i});
end
tmp1 = brewermap(36, '*Blues');
tmp2 = brewermap(36, 'Reds');
tmp3 = brewermap(36, 'Greens');
cmap{end+1,1} = [tmp1(1:32,:); tmp2(5:36,:)];
cmap{end,2} = 'Blues-Reds';
cmap{end+1,1} = [tmp1(1:32,:); tmp3(5:36,:)];
cmap{end,2} = 'Blues-Greens';
bmap2 = {'Accent' 'Dark2' 'Paired' 'Pastel1' 'Pastel2' 'Set1' 'Set2' 'Set3'};
bnum2 = [8 8 12 9 8 9 8 12];
anchor = size(cmap,1);
for i = 1:length(bmap2)
cmap{anchor+i,1} = cmap_upsample(brewermap(bnum2(i), bmap2{i}), depth);
cmap{anchor+i,2} = sprintf('%s (%d)', bmap2{i}, bnum2(i));
end
function urls = default_urls
urls = {
'SPM' 'http://www.fil.ion.ucl.ac.uk/spm/'
'SPM Listserv' 'https://www.jiscmail.ac.uk/cgi-bin/webadmin?REPORT&z=4&1=spm&L=spm'
'SnPM' 'http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/nichols/software/snpm/'
'FSL' 'http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/'
'AFNI' 'https://afni.nimh.nih.gov/afni/'
'Freesurfer' 'http://www.freesurfer.net/'
'Caret' 'http://brainvis.wustl.edu/wiki/index.php/Caret:About'
'MIALAB' 'http://mialab.mrn.org/software/'
'NITRC' 'https://www.nitrc.org/'
'Tom Nichols Software' 'http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/nichols/software/'
'Aaron Schultz Software (MR Tools)' 'http://mrtools.mgh.harvard.edu/index.php/Main_Page'
'NeuroVault' 'http://neurovault.org'
'NeuroPowerTools' 'http://neuropowertools.org'
'Human Connectome Project' 'http://www.humanconnectome.org/software/'
'Brain Imaging Data Structure' 'http://bids.neuroimaging.io/'
'Neuroimaging Data Model' 'http://nidm.nidash.org/'
'NeuroLex' 'http://neurolex.org/wiki/Main_Page'
};
urls = cell2struct(urls, {'label' 'url'}, 2);
function fmt = default_saveformats
fmt = {
'*.pdf', 'Portable Document Format (*.pdf)';
'*.eps', 'Encapsulated Postscript (*.eps)';
'*.svg', 'Scalable Vector Graphics (*.svg)';
'*.jpg', 'JPEG (*.jpg)';
'*.png', 'Portable Network Graphics (*.png)';
'*.bmp', 'Bitmap (*.bmp)';
'*.ps', 'PostScript (*.ps)';
'*.tiff', 'TIFF (*.tiff)'
};
function labs = default_labels
labs = struct( ...
'atlasname' , 'AnatomyToolbox' , ...
'alphacorrect' , .05 , ...
'separation' , 20 , ...
'numpeaks' , 3 , ...
'alphauncorrect', .001 , ...
'clusterextent' , 5 , ...
'surfshow' , 4 , ...
'surface' , 'Inflated' , ...
'shading' , 'Sulc' , ...
'nverts' , 40962 , ...
'round' , false , ...
'neighbor' , 0 , ...
'dilate' , false , ...
'shadingmin' , .15 , ...
'shadingmax' , .70 , ...
'colorbar' , true ...
);
function uicell = default_lowerpane
global st
prop = default_properties('units', 'norm', 'fontn', 'arial', 'fonts', st.fonts.sz2);
uicell = { ...
1, 4, 1, 'Current Location' , 'uititle' , prop.text ; ...
2, 4, 1, '' , 'Location' , [prop.edit {'Enable', 'Inactive'}] ; ...
3, 1, 1, '' , 'rowspacer' , [] ; ...
4, 4, 3, 'Value' , 'uilabel' , prop.text ; ...
4, 4, 5, 'Coordinate' , 'uilabel' , prop.text ; ...
4, 4, 3, 'ClusterSize' , 'uilabel' , prop.text ; ...
5, 4, 3, '' , 'voxval' , [prop.edit {'Enable', 'Inactive'}] ; ...
5, 4, 5, '' , 'xyz' , [prop.edit {'Callback', @cb_changexyz}] ; ...
5, 4, 3, '' , 'clustersize' , [prop.edit {'Enable', 'Inactive'}] ; ...
6, 2, 1, '' , 'rowspacer' , [] ; ...
7, 4, 1, 'Threshold' , 'uititle' , prop.text ; ...
8, 4, 3, 'Extent' , 'uilabel' , prop.text ; ...
8, 4, 4, 'Thresh' , 'uilabel' , prop.text ; ...
8, 4, 6, 'P-Value' , 'uilabel' , prop.text ; ...
9, 4, 3, '' , 'Extent' , [prop.edit {'Callback', @cb_updateoverlay}] ; ...
9, 4, 4, '' , 'Thresh' , [prop.edit {'Callback', @cb_updateoverlay}] ; ...
9, 4, 6, '' , 'P-Value' , [prop.edit {'Callback', @cb_updateoverlay}] ; ...
10, 1, 1, '' , 'rowspacer' , [] ; ...
11, 4, 2, 'DF' , 'uilabel' , prop.text ; ...
11, 4, 5, 'Type' , 'uilabel' , prop.text ; ...
12, 4, 2, '' , 'DF' , [prop.edit {'Callback', @cb_updateoverlay}] ; ...
12, 4, 5, {'User-specified' 'Voxel FWE' 'Cluster FWE' 'Cluster FDR'} , 'Correction' , [prop.popup {'Value', 1, 'Callback', @cb_correct}] ...
};
function uicell = default_upperpane
global st
prop = default_properties('units', 'norm', 'fontn', 'arial');
uicell = { ...
1, 1, 1, '' , 'rowspacer' , [] ; ...
2, 5, 4, 'Direction' , 'uititle' , prop.text ; ...
2, 5, 2, '+' , 'direct' , [prop.radio {'fontunits', 'points', 'pos', [0 0 1 1], 'Callback', @cb_directmenu}] ; ...
2, 5, 2, '-' , 'direct' , [prop.radio {'fontunits', 'points', 'pos', [0 0 1 1], 'Callback', @cb_directmenu}] ; ...
2, 5, 3, '+/-' , 'direct' , [prop.radio {'fontunits', 'points', 'pos', [0 0 1 1], 'Callback', @cb_directmenu}] ; ...
2, 5, .5, '' , 'rowspacer' , [] ; ...
2, 5, 4, 'Colormap' , 'uititle' , [prop.text {'fontsize', st.fonts.sz3}] ; ...
2, 5, 4, st.cmap(:,2) , 'colormaplist' , [prop.popup {'Value', 1, 'pos', [0 0 1 .95], 'Callback', @setcolormap, 'fonts', st.fonts.sz3}] ; ...
2, 5, 2, '' , 'minval' , [prop.edit {'pos', [0 .10 1 .80], 'Callback', @cb_minval, 'fonts', st.fonts.sz3}] ; ...
2, 5, 2, '' , 'maxval' , [prop.edit {'pos', [0 .10 1 .80], 'Callback', @cb_maxval, 'fonts', st.fonts.sz3}] ; ...
3, 1, 1, '' , 'rowspacer' , [] ; ...
};
% | GUI COMPONENTS
% =========================================================================
function S = put_figure(ol, ul)
default_preferences(1);
% | Check for open GUI, close if one is found
delete(findobj(0, 'tag', 'bspmview'));
global st
% | Setup new fig
if isfield(st.preferences, 'fontname'), st.fonts.name = st.preferences.fontname; end
if isfield(st.preferences, 'color')
st.color = st.preferences.color;
else
st.color = default_colors;
end
S.hFig = figure(...
'Name', abridgepath(ol), ...
'Units', 'pixels', ...
'Position',st.pos.gui,...
'Resize','off',...
'Color',st.color.bg,...
'ColorMap',gray(64),...
'NumberTitle','off',...
'DockControls','off',...
'MenuBar','none',...
'Tag', 'bspmview', ...
'CloseRequestFcn', @cb_closegui, ...
'DefaultTextColor', st.color.font,...
'DefaultTextInterpreter','none',...
'DefaultTextFontName','Arial',...
'DefaultTextFontSize',st.fonts.sz6,...
'DefaultAxesColor',st.color.border,...
'DefaultAxesXColor',st.color.border,...
'DefaultAxesYColor',st.color.border,...
'DefaultAxesZColor',st.color.border,...
'DefaultAxesFontName','Arial',...
'DefaultPatchFaceColor',st.color.fg,...
'DefaultPatchEdgeColor',st.color.fg,...
'DefaultSurfaceEdgeColor',st.color.fg,...
'DefaultLineColor',st.color.border,...
'DefaultUicontrolFontName',st.fonts.name,...
'DefaultUicontrolFontSize',st.fonts.sz3,...
'DefaultUicontrolInterruptible','on',...
'Visible','off',...
'Toolbar','none');
uicontrol('Parent', S.hFig, 'Units', 'Normal', 'Style', 'Text', ...
'pos', [0 0 1 .001], 'backg', st.color.blues(8,:));
uicontrol('Parent', S.hFig, 'Units', 'Normal', 'Style', 'Text', ...
'pos', [0 .001 .001 1], 'backg', st.color.blues(10,:));
uicontrol('Parent', S.hFig, 'Units', 'Normal', 'Style', 'Text', ...
'pos', [.999 .001 .001 .999], 'backg', st.color.blues(10,:));
% | REGISTRY OBJECT (HREG)
S.hReg = uipanel('Parent',S.hFig,'Units','Pixels','Position',st.pos.pane.axes,...
'BorderType', 'none', 'BackgroundColor',st.color.bg);
set(S.hReg, 'units', 'norm');
[st.fig, st.figax, st.direct] = deal(S.hFig, S.hReg, '+/-');
bspm_orthviews('Reset');
st.cmap = default_colormaps(64);
load_overlay(ol, st.preferences.alphauncorrect, st.preferences.clusterextent);
bspm_XYZreg('InitReg',S.hReg,st.ol.M,st.ol.DIM,[0;0;0]); % initialize registry object
st.ho = bspm_orthviews('Image', ul, [.025 .025 .95 .95]);
bspm_orthviews('Register', S.hReg);
bspm_orthviews('MaxBB');
setposition_axes;
setxhaircolor;
put_figmenu;
put_upperpane;
put_lowerpane;
put_axesxyz;
put_axesmenu;
setthresh(st.ol.C0(3,:), find(strcmpi({'+', '-', '+/-'}, st.direct)));
if find(strcmpi({'+', '-', '+/-'}, st.direct))==3, disablefdr; end
setmaxima;
setcolormap;
setfontunits('points');
setunits;
check4design;
cb_minmax;
if nargout, S.handles = gethandles; end
function put_startupmsg
global st bspmview_version
st.version.bspmview = bspmview_version;
[v,r] = spm('Ver','',1);
st.version.spm = sprintf('%s_r%s', v, r);
st.version.matlab = version;
st.version.computer = computer;
[mv, mstr] = version;
matlabyear = str2double(regexp(mstr, '\d\d\d\d$', 'match'));
if matlabyear < 2014
fprintf(['\nWARNING: This software has only been tested on MATLAB R2014a and later.' ...
'\nYou are using MATLAB v%s. You may encounter errors.\n\n'], st.version.matlab);
end
if str2double(r) < 6313
fprintf(['\nWARNING: This software has only been tested with SPM8 (r6313) and SPM12.' ...
'\nYou are currently using %s (%s). You may encounter errors.\n\n'], v, r);
end
printmsg(sprintf('Started %s', nicetime), sprintf('BSPMVIEW v.%s', bspmview_version));
function put_upperpane(varargin)
global st
cnamepos = [.01 .15 .98 .85];
prop = default_properties('units', 'norm', 'fontn', 'arial', 'fonts', st.fonts.sz3);
panelh = uipanel('parent',st.fig, prop.panel{:}, 'pos', st.pos.pane.upper, 'tag', 'upperpanel');
uicell = default_upperpane;
griddim = cell2mat(uicell(:,1:3));
lowpanedim = unique(griddim(:,1:2), 'rows');
nrow = size(lowpanedim, 1);
[phandle, pidx] = pgrid(nrow, 1, ...
'parent', panelh, ...
'relheight', lowpanedim(:,2), ...
'panelsep', 0, ...
'marginsep', .01, ...
'backg', st.color.bg, ...
'foreg', st.color.fg);
uihandles = [];
for r = 1:nrow
spec = uicell(griddim(:,1)==r, 3:end);
ncol = size(spec, 1);
if ncol > 1
chandle = pgrid(1, ncol, ...
'parent', phandle(r), ...
'relwidth', cell2mat(spec(:,1)), ...
'panelsep', .01, ...
'marginsep', 0, ...
'backg', st.color.bg, ...
'foreg', st.color.fg);
else
chandle = phandle(r);
end
uihandles = [uihandles; chandle];
end
spaceridx = cellfun('isempty', uicell(:,end));
uihandles(spaceridx) = [];
uicell(spaceridx,:) = [];
for i = 1:length(uihandles), ph(i) = uicontrol(uihandles(i), 'string', uicell{i, 4}, uicell{i, 6}{:}, 'pos', [0 0 1 1], 'tag', uicell{i, 5}); drawnow; end
set(findall(panelh, 'tag', 'uititle'), 'fontsize', st.fonts.sz2, 'fontweight', 'bold');
% | Check valid directions for contrast display
allh = findobj(st.fig, 'Tag', 'direct');
set(allh, 'FontSize', st.fonts.sz2*1.25);
allhstr = get(allh, 'String');
if any(st.ol.null)
opt = {'+' '-'};
set(allh(strcmpi(allhstr, '+/-')), 'Value', 0, 'Enable', 'inactive', 'Visible', 'on');
set(allh(strcmpi(allhstr, opt{st.ol.null})), 'Value', 0, 'Enable', 'inactive', 'Visible', 'on');
set(allh(strcmpi(allhstr, opt{st.ol.null==0})), 'Value', 1, 'Enable', 'inactive');
else
set(allh(strcmpi(allhstr, '+/-')), 'value', 1, 'enable', 'inactive');
end
set(panelh, 'units', 'norm');
drawnow;
function put_lowerpane(varargin)
global st
% | UNITS
figpos = get(st.fig, 'pos');
axpos = get(st.figax, 'pos');
figw = figpos(3);
axw = axpos(3);
% | PANEL
[h,subaxpos] = gethandles_axes;
lowpos = subaxpos(1,:);
lowpos(1) = subaxpos(3, 1) + .01;
lowpos(3) = 1 - lowpos(1);
prop = default_properties('units', 'norm', 'fontn', 'arial', 'fonts', st.fonts.sz2);
panelh = uipanel('parent', st.figax, prop.panel{:}, 'pos',lowpos, 'tag', 'lowerpanel');
uicell = default_lowerpane;
griddim = cell2mat(uicell(:,1:3));
lowpanedim = unique(griddim(:,1:2), 'rows');
nrow = size(lowpanedim, 1);
[phandle, pidx] = pgrid(nrow, 1, ...
'parent', panelh, ...
'relheight', lowpanedim(:,2), ...
'panelsep', .01, ...
'marginsep', .025, ...
'backg', st.color.bg, ...
'foreg', st.color.fg);
uihandles = [];
for r = 1:nrow
spec = uicell(griddim(:,1)==r, 3:end);
ncol = size(spec, 1);
if ncol > 1
chandle = pgrid(1, ncol, ...
'parent', phandle(r), ...
'relwidth', cell2mat(spec(:,1)), ...
'panelsep', .025, ...
'marginsep', 0, ...
'backg', st.color.bg, ...
'foreg', st.color.fg);
else
chandle = phandle(r);
end
uihandles = [uihandles; chandle];
end
spaceridx = cellfun('isempty', uicell(:,end));
uihandles(spaceridx) = [];
uicell(spaceridx,:) = [];
for i = 1:length(uihandles), ph(i) = uicontrol(uihandles(i), 'string', uicell{i, 4}, uicell{i, 6}{:}, 'pos', [0 0 1 1], 'tag', uicell{i, 5}); drawnow; end
set(findall(panelh, 'tag', 'uititle'), 'fontsize', st.fonts.sz1, 'fontweight', 'bold');
set(findall(panelh, 'Enable', 'Inactive'), 'backg', st.color.fg*.80);
set(panelh, 'units', 'norm');
setthreshinfo;
function put_figmenu
global st
global bspmview_version
%% Main Menu
S.menu1 = uimenu('Parent', st.fig, 'Label', 'bspmVIEW');
S.version = uimenu(S.menu1, 'Label', sprintf('v.%s', bspmview_version) , 'Enable', 'off');
S.checkversion = uimenu(S.menu1, 'Label', 'Check for Updates', 'Callback', @cb_checkversion);
S.appear = uimenu(S.menu1, 'Label','Appearance', 'Separator', 'on');
S.skin = uimenu(S.appear, 'Label', 'Skin');
% if isfield(st.preferences, 'light')
% S.changeskin(1) = uimenu(S.skin, 'Label', 'Dark', 'Checked', st.preferences.dark, 'Callback', @cb_changeskin);
% S.changeskin(2) = uimenu(S.skin, 'Label', 'Light', 'Checked', st.preferences.light, 'Separator', 'on', 'Callback',@cb_changeskin);
% else
S.changeskin(1) = uimenu(S.skin, 'Label', 'Dark', 'Checked', 'on', 'Callback', @cb_changeskin);
S.changeskin(2) = uimenu(S.skin, 'Label', 'Light', 'Separator', 'on', 'Callback',@cb_changeskin);
% end
S.guisize = uimenu(S.appear, 'Label','GUI Size');
S.gui(1) = uimenu(S.guisize, 'Label', 'Increase', 'Accelerator', 'i', 'Callback', @cb_changeguisize);
S.gui(2) = uimenu(S.guisize, 'Label', 'Decrease', 'Accelerator', 'd', 'Separator', 'on', 'Callback',@cb_changeguisize);
S.fontsize = uimenu(S.appear, 'Label','Font Size');
S.font(1) = uimenu(S.fontsize, 'Label', 'Increase', 'Accelerator', '=', 'Callback', @cb_changefontsize);
S.font(2) = uimenu(S.fontsize, 'Label', 'Decrease', 'Accelerator', '-', 'Callback',@cb_changefontsize);
% S.fontname = uimenu(S.appear, 'Label','Font Name', 'Callback', @cb_changefontname);
% S.setasdef = uimenu(S.appear, 'Label', 'Set Current as Default', 'Separator', 'on', 'Callback', @cb_setasdefault);
%% Help Menu
S.helpme = uimenu(S.menu1,'Label','Help', 'Separator', 'on');
S.helpme1 = uimenu(S.helpme,'Label','Online Manual', 'CallBack', {@cb_web, 'http://spunt.github.io/bspmview/'});
S.helpme2 = uimenu(S.helpme,'Label','Online Issues Forum', 'CallBack', {@cb_web, 'https://github.com/spunt/bspmview/issues'});
S.helpme3 = uimenu(S.helpme,'Label','Submit Issue or Feature Request', 'CallBack', {@cb_web, 'https://github.com/spunt/bspmview/issues/new'});
S.debug = uimenu(S.helpme,'Label','Debug', 'Separator', 'on');
S.debug1 = uimenu(S.debug, 'Label','Open GUI M-File', 'Callback', @cb_opencode);
S.debug2 = uimenu(S.debug, 'Label','Run UIINSPECT', 'Callback', @cb_uiinspect);
S.exit = uimenu(S.menu1, 'Label', 'Exit', 'Separator', 'on', 'Callback', {@cb_closegui, st.fig});
%% Make sure resize callbacks are registered one at a time
set(S.gui, 'BusyAction', 'cancel', 'Interruptible', 'off');
set(S.font, 'BusyAction', 'cancel', 'Interruptible', 'off');
%% Load Menu
S.load = uimenu(st.fig,'Label','Load', 'Separator', 'on');
S.loadol = uimenu(S.load,'Label','New Overlay', 'Accelerator', 'o', 'CallBack', @cb_loadol);
S.resetol = uimenu(S.load,'Label','Current Overlay (Reload)', 'CallBack', @cb_resetol);
S.loadul = uimenu(S.load,'Label','New Underlay', 'Accelerator', 'u', 'Separator', 'on', 'CallBack', @cb_loadul);
%% Save Menu
S.save = uimenu(st.fig,'Label','Save', 'Separator', 'on');
S.saveintensity = uimenu(S.save,'Label','Save Suprathreshold (Intensity)','CallBack', @cb_saveimg);
S.savemask = uimenu(S.save,'Label','Save Suprathreshold (Binary Mask)', 'CallBack', @cb_saveimg);
S.ctsavemap = uimenu(S.save,'Label', 'Save Current Cluster (Intensity)', 'callback', @cb_saveclust, 'separator', 'on');
S.ctsavemask = uimenu(S.save,'Label', 'Save Current Cluster (Binary Mask)', 'callback', @cb_saveclust);
S.saveroi = uimenu(S.save,'Label', 'Save ROI at Current Location', 'CallBack', @cb_saveroi);
S.savetable = uimenu(S.save,'Label','Save Results Table', 'Separator', 'on', 'CallBack', @cb_savetable, 'separator', 'on');
S.savergb = uimenu(S.save,'Label','Save Screen Capture', 'callback', @cb_savergb);
%% Options Menu
S.options = uimenu(st.fig,'Label','Display', 'Separator', 'on');
S.prefs = uimenu(S.options, 'Label','Preferences', 'Accelerator', 'P', 'Callback', @cb_preferences);
S.report = uimenu(S.options,'Label','Show Results Table', 'Accelerator', 't', 'Separator', 'on', 'CallBack', @cb_report);
S.render = uimenu(S.options,'Label','Show Surface Rendering', 'Accelerator', 'r', 'CallBack', @cb_render);
S.slice = uimenu(S.options,'Label','Show Slice Montage', 'Accelerator', 's', 'CallBack', @cb_montage);
S.smoothmap = uimenu(S.options,'Label','Apply Smoothing to Overlay', 'Separator', 'on', 'CallBack', @cb_smooth);
S.smoothmap = uimenu(S.options,'Label','Apply Mask to Overlay','CallBack', @cb_mask);
S.xhairtoggle = uimenu(S.options, 'Label', 'Toggle Crosshairs', 'Accelerator', 'c', 'Tag', 'Crosshairs', 'Checked', 'on', 'CallBack', {@cb_crosshair, 'toggle'}, 'Separator', 'on');
S.xhaircolor = uimenu(S.options, 'Label', 'Change Crosshair Color', 'CallBack', {@cb_crosshair, 'color'});
S.reversemap = uimenu(S.options,'Label','Reverse Color Map', 'Tag', 'reversemap', 'Checked', 'off', 'CallBack', @cb_reversemap, 'Separator', 'on');
%% Web Menu
S.web(1) = uimenu(st.fig,'Label','Web', 'Separator', 'on');
urls = default_urls;
for i = 1:length(urls), S.web(i+1) = uimenu(S.web(1),'Label',urls(i).label, 'Callback', {@cb_web, urls(i).url}); end
S.web(length(urls)+1) = uimenu(S.web(1),'Label','Search Location in Neurosynth', 'CallBack', @cb_neurosynth);
%% Status
S.status = uimenu(st.fig, 'Label', '| Status: Ready', 'Enable', 'off', 'Tag', 'status');
function put_axesmenu
[h,axpos] = gethandles_axes;
cmenu = uicontextmenu;
ctmax = uimenu(cmenu, 'Label', 'Go to Global Peak', 'callback', @cb_minmax, 'separator', 'off');
ctlocalmax = uimenu(cmenu, 'Label', 'Go to Nearest Peak', 'callback', @cb_localmax);
ctclustmax = uimenu(cmenu, 'Label', 'Go to Cluster Peak', 'callback', @cb_clustminmax);
ctplot = uimenu(cmenu, 'Label', 'Plot', 'separator', 'on');
spaceopt = {'Cluster' 'Voxel' 'Shape around Voxel'};
dataopt = {'Raw' 'Whitened And Filtered'};
for c = 1:length(spaceopt)
hs(c) = uimenu(ctplot, 'Label', spaceopt{c});
for i = 1:length(dataopt)
uimenu(hs(c), 'Label', dataopt{i}, 'callback', {@cb_clustexplore, spaceopt{c}, dataopt{i}});
end
end
ctsave = uimenu(cmenu, 'Label', 'Save', 'separator', 'on');
ctsavemap = uimenu(ctsave, 'Label', 'Save Current Cluster (Intensity)', 'callback', @cb_saveclust);
ctsavemask = uimenu(ctsave, 'Label', 'Save Current Cluster (Binary Mask)', 'callback', @cb_saveclust);
ctsaveroi = uimenu(ctsave, 'Label', 'Save ROI at Current Location', 'callback', @cb_saveroi);
ctsavergb = uimenu(ctsave, 'Label', 'Save Screen Capture', 'callback', @cb_savergb);
ctns = uimenu(cmenu, 'Label', 'Search Location in Neurosynth', 'CallBack', @cb_neurosynth, 'separator', 'on');
ctxhair = uimenu(cmenu, 'Label', 'Toggle Crosshairs', 'checked', 'on', 'Accelerator', 'c', 'Tag', 'Crosshairs', 'callback', {@cb_crosshair, 'toggle'}, 'separator', 'on');
for a = 1:3
set(h.ax(a), 'uicontextmenu', cmenu);
end
drawnow;
function put_axesxyz
global st
h = gethandles_axes;
xyz = round(bspm_XYZreg('GetCoords',st.registry.hReg));
xyzstr = num2str([-99; xyz]); xyzstr(1,:) = [];
set(h.ax, 'YAxislocation', 'right');
axidx = [3 2 1];
for a = 1:length(axidx)
yh = get(h.ax(axidx(a)), 'YLabel');
st.vols{1}.ax{axidx(a)}.xyz = yh;
if a==1
set(yh, 'units', 'norm', 'fontunits', 'norm', 'fontsize', .075, ...
'pos', [0 1 0], 'horiz', 'left', 'fontname', 'arial', ...
'color', [1 1 1], 'string', xyzstr(a,:), 'rot', 0, 'tag', 'xyzlabel');
set(yh, 'fontunits', 'points');
fs = get(yh, 'fontsize');
else
set(yh, 'units', 'norm', 'fontsize', fs, ...
'pos', [0 1 0], 'horiz', 'left', 'fontname', 'arial', ...
'color', [1 1 1], 'string', xyzstr(a,:), 'rot', 0, 'tag', 'xyzlabel');
end
end
drawnow;
function put_upperpaneinfo(parent)
global st
data = struct2cell(st.ol.finfo);
data = data(2:3);
th = uitable('Parent', parent, ...
'Data', data, ...
'Units', 'norm', ...
'ColumnName', [], ...
'RowName', [], ...
'Pos', [0 0 1 1], ...
'RearrangeableColumns', 'on', ...
'ColumnWidth', 'auto', ...
'FontName', 'Fixed-Width', ...
'FontUnits', 'Points', ...
'FontSize', st.fonts.sz4);
% | Column Width
set(th, 'units', 'pix');
set(parent, 'units', 'pix');
textent = get(th, 'extent');
tpos = get(th, 'Pos');
fpos = get(parent, 'pos');
ht = diff([tpos([2 4])]);
hw = diff([fpos([1 3])])*.975;
tpos(2) = [tpos(4) - textent(4)];
tpos(4) = textent(4);
set(th, 'ColumnWidth', {hw}, 'Position', tpos);
set(parent, 'units', 'pix');
set(th, 'units', 'norm');
drawnow;
% | CALLBACKS - THRESHOLDING
% =========================================================================
function cb_updateoverlay(varargin)
global st
% | Check for Numeric Input
% if isempty(varargin) || isnan(str2double(get(varargin{1}, 'string')))
% setthreshinfo;
% return
% end
htype = findobj(st.fig, 'tag', 'Correction');
htypestr = get(htype, 'string');
userstr = 'User-specified';
T0 = getthresh;
T = T0;
di = strcmpi({'+' '-' '+/-'}, T.direct);
if nargin > 0
tag = get(varargin{1}, 'tag');
switch tag
case {'Thresh'}
if T.df~=Inf, T.pval = bob_t2p(T.thresh, T.df); end
if find(strcmpi(htypestr, 'Cluster FWE'))==get(htype, 'value')
T.extent = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
elseif find(strcmpi(htypestr, 'Cluster FDR'))==get(htype, 'value')
[tmp, T.extent] = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
else
set(htype, 'value', find(strcmpi(htypestr, userstr)));
end
case {'P-Value'}
if T.df~=Inf, T.thresh = spm_invTcdf(1-T.pval, T.df); end
if find(strcmpi(htypestr, 'Cluster FWE'))==get(htype, 'value')
T.extent = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
elseif find(strcmpi(htypestr, 'Cluster FDR'))==get(htype, 'value')
[tmp, T.extent] = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
else
set(htype, 'value', find(strcmpi(htypestr, userstr)));
end
case {'DF'}
if ~any([T.pval T.df]==Inf)
T.thresh = spm_invTcdf(1-T.pval, T.df);
T.pval = bob_t2p(T.thresh, T.df);
end
if find(strcmpi(htypestr, 'Cluster FWE'))==get(htype, 'value')
T.extent = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
elseif find(strcmpi(htypestr, 'Cluster FDR'))==get(htype, 'value')
[tmp, T.extent] = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);;
else
set(htype, 'value', find(strcmpi(htypestr, userstr)));
end
case {'Extent'}
if find(strcmpi(htypestr, 'Cluster FWE'))==get(htype, 'value')
set(htype, 'value', find(strcmpi(htypestr, userstr)));
elseif find(strcmpi(htypestr, 'Cluster FDR'))==get(htype, 'value')
set(htype, 'value', find(strcmpi(htypestr, userstr)));
end
if sum(st.ol.C0(di,st.ol.C0(di,:)>=T.extent))==0
headsup('No suprathreshold clusters. Setting extent to largest cluster size at current intensity threshold.');
T.extent = max(st.ol.C0(di,:));
end
end
end
[st.ol.C0, st.ol.C0IDX] = getclustidx(st.ol.Y, T.thresh, T.extent);
C = st.ol.C0(di,:);
if sum(C(C>=T.extent))==0
setthreshinfo;
headsup('No suprathreshold voxels. Reverting to previous threshold.');
return
end
setthresh(C, find(di));
setthreshinfo(T);
setmaxima;
drawnow;
function cb_correct(varargin)
setstatus('Working, please wait...');
global st
str = get(varargin{1}, 'string');
methodstr = str{get(varargin{1}, 'value')};
T0 = getthresh;
T = T0;
di = strcmpi({'+' '-' '+/-'}, T.direct);
switch methodstr
case {'User-specified'}
cb_resetol;
setstatus('Ready');
return;
case {'Voxel FWE'}
T.thresh = voxel_correct(st.ol.fname, st.preferences.alphacorrect);
T.pval = bob_t2p(T.thresh, T.df);
case {'Cluster FWE'}
T.extent = cluster_correct(st.ol.fname, T0.pval, st.preferences.alphacorrect);
case {'Cluster FDR'}
[tmp, T.extent] = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);
end
[st.ol.C0, st.ol.C0IDX] = getclustidx(st.ol.Y, T.thresh, T.extent);
C = st.ol.C0(di,:);
if sum(C(C>=T.extent))==0
T0.thresh = st.ol.U;
setthreshinfo(T0);
headsup('No suprathreshold voxels. Reverting to previous threshold.');
set(varargin{1}, 'value', 1);
setstatus('Ready');
return
end
setthresh(C, find(di));
setthreshinfo(T);
setstatus('Ready');
function cb_directmenu(varargin)
global st
if ischar(varargin{1}), str = varargin{1};
else str = get(varargin{1}, 'string'); end
% | See If Colormap Update is in Order
if ismember(str, {'+' '-'}) & strcmp(st.direct, '+/-')
htmp = findobj(st.fig, 'Tag', 'colormaplist');
set(htmp, 'value', find(strcmpi(get(htmp, 'String'), 'hot')));
enablefdr;
elseif strcmp(str, '+/-')
htmp = findobj(st.fig, 'Tag', 'colormaplist');
set(htmp, 'value', find(strcmpi(get(htmp, 'String'), 'signed')));
disablefdr;
end
allh = findobj(st.fig, 'Tag', 'direct');
allhstr = get(allh, 'String');
set(allh(strcmp(allhstr, str)), 'Value', 1, 'Enable', 'inactive');
set(allh(~strcmp(allhstr, str)), 'Value', 0, 'Enable', 'on');
drawnow;
T = getthresh;
di = strcmpi({'+' '-' '+/-'}, T.direct);
[st.ol.C0, st.ol.C0IDX] = getclustidx(st.ol.Y, T.thresh, T.extent);
C = st.ol.C0(di,:);
y = st.ol.Y(C>0);
ydi = [any(y>0) any(y<0) (any(y>0) & any(y<0))];
if ~ydi(di)
lab = {'positive' 'negative'};
if find(di)==3 && any(ydi)
headsup(sprintf('No %s suprathreshold voxels. Showing unthresholded image.', lab{ydi(1:2)==0}));
else
headsup('No suprathreshold voxels. Showing unthresholded image.');
end
T.thresh = 0.0001;
T.pval = bob_t2p(T.thresh, T.df);
T.extent = 1;
[st.ol.C0, st.ol.C0IDX] = getclustidx(st.ol.Y, T.thresh, T.extent);
C = st.ol.C0(di,:);
end
opt = default_lowerpane;
opt = opt{strcmp(opt(:,5), 'Correction'), 4};
cmethod = opt{get(findobj(st.fig, 'Tag', 'Correction'), 'Value')};
if all([ismember(str, {'+' '-'}), ismember(st.direct, {'+' '-'}), strcmpi(cmethod, opt{4})])
[tmp, T.extent] = cluster_correct(st.ol.fname, T.pval, st.preferences.alphacorrect);
end
setthreshinfo(T);
setthresh(C, find(di));
% | CALLBACKS - BSPMVIEW MENU