1-
21function transparentMontage(opt )
32 %
43 % Generate montage with transparent plotting
@@ -11,134 +10,137 @@ function transparentMontage(opt)
1110
1211 % (C) Copyright 2025 bidspm developers
1312
14- overwrite = true ;
15-
16- color_map_folder = fullfile(returnRootDir(), ' lib' , ' brain_colours' , ' mat_maps' );
17-
18- for i_node = 1 : numel(opt .model .bm .Nodes )
19-
20- node = opt.model.bm.Nodes{i_node };
21-
13+ for i_node = 1 : numel(opt .model .bm .Nodes )
14+
15+ node = opt.model.bm.Nodes{i_node };
16+
2217 if any(strcmp(node .Level , {' Run' , ' Subject' }))
23-
24- for iSub = 1 : numel(opt .subjects )
25-
26- subLabel = opt.subjects{iSub };
27-
28- ffxDir = getFFXdir(subLabel , opt );
29- load(fullfile(ffxDir , ' SPM.mat' ))
30-
31- for iRes = 1 : numel(node .Model .Software .bidspm .Results )
32-
33- opt.results = node.Model.Software.bidspm.Results{iRes };
34-
35- if ~isfield(opt .results , ' montage' ) || ~opt .results .montage .do
36- continue
37- end
38-
39- % set defaults
40- [opt , ~ ] = checkMontage(opt , iRes , node , struct([]), subLabel );
41- opt = checkOptions(opt );
42- opt .results(iRes ).montage = setMontage(opt .results(iRes ));
43-
44- for i_name = 1 : numel(opt .results .name )
45-
46- if opt .results(iRes ).binary
47- layers = sd_config_layers(' init' , {' truecolor' , ' dual' , ' contour' });
48- else
49- layers = sd_config_layers(' init' , {' truecolor' , ' dual' });
50- end
51-
52- %% Layer 1: Anatomical map
53- layers(1 ) = setFields(layers(1 ), opt .results(iRes ).sdConfig.layers{1 }, overwrite );
54-
55- layers(1 ).color.file = opt .results(iRes ).montage.background{1 };
56-
57- hdr = spm_vol(layers(1 ).color.file);
58- [max_val , ~ ] = slover(' volmaxmin' , hdr );
59- layers(1 ).color.range = [0 max_val ];
60-
61- %% Layer 2: Dual-coded layer
62-
63- % - contrast estimates color-coded;
64- layers(2 ) = setFields(layers(2 ), opt .results(iRes ).sdConfig.layers{2 }, overwrite );
65-
66- name = opt.results.name{i_name };
67- tmp = struct(' name' , name );
68- contrastNb = getContrastNb(tmp , opt , SPM );
69-
70- % keep track if this is a t test or F test
71- stat = SPM .xCon(contrastNb ).STAT;
72-
73- contrastNb = sprintf(' %04.0f ' , contrastNb );
74-
75- if strcmp(stat , ' T' )
76- colorFile = spm_select(' FPList' , ffxDir , [' ^con_' contrastNb ' .nii$' ]);
77- else
78- colorFile = spm_select(' FPList' , ffxDir , [' ^ess_' contrastNb ' .nii$' ]);
79- end
80- layers(2 ).color.file = colorFile ;
81-
82- title = strrep(name , ' _' , ' ' );
83- layers(2 ).color.label = [title ' (a.u.)' ];
84-
85- % - statistics opacity-coded
86- if strcmp(stat , ' T' )
87- opacityFile = spm_select(' FPList' , ffxDir , [' ^spmT_' contrastNb ' .nii$' ]);
88-
89- layers(2 ).opacity.label = ' | t |' ;
90-
91- load(fullfile(color_map_folder , ' diverging_bwr_iso.mat' )); % #ok<*LOAD>
92- layers(2 ).color.map = diverging_bwr ;
93- else
94- opacityFile = spm_select(' FPList' , ffxDir , [' ^spmF_' contrastNb ' .nii$' ]);
95-
96- layers(2 ).opacity.label = ' F' ;
97-
98- load(fullfile(color_map_folder , ' 1hot_iso.mat' ));
99- layers(2 ).color.map = hot ;
100-
101- hdr = spm_vol(opacityFile );
102- [max_val , ~ ] = slover(' volmaxmin' , hdr );
103- layers(2 ).color.range = [0 max_val ];
104-
105- layers(2 ).opacity.range = [0 5 ];
106- end
107- layers(2 ).opacity.file = opacityFile ;
108-
109- %% Contour
110- if opt .results(iRes ).binary
111- layers(3 ) = setFields(layers(3 ), opt .results(iRes ).sdConfig.layers{3 }, overwrite );
112- contour = spm_select(' FPList' , ffxDir , [' ^sub.*' contrastNb ' .*_mask.nii' ]);
113- layers(3 ).color.file = contour ;
114- end
115-
116- %% Settings
117- settings = opt .results(iRes ).sdConfig.settings;
118-
119- % we reuse the details for the SPM montage
120- settings.slice.disp_slices = opt .results(1 ).montage.slices;
121- settings.slice.orientation = opt .results(1 ).montage.orientation;
122-
123- settings.fig_specs.title = title ;
124-
125- %% Display the layers
126- [~ , ~ , h_figure ] = sd_display(layers , settings );
127-
128- outputFile = fullfile(ffxDir , [contrastNb ' _' name ' .png' ]);
129- print(h_figure , outputFile , ' -dpng' );
130- close(h_figure )
131-
132- % TODO
133- % rename file
134-
135-
136- end
137-
138- end
139-
18+
19+ for iSub = 1 : numel(opt .subjects )
20+
21+ subLabel = opt.subjects{iSub };
22+
23+ ffxDir = getFFXdir(subLabel , opt );
24+ load(fullfile(ffxDir , ' SPM.mat' ));
25+
26+ for iRes = 1 : numel(node .Model .Software .bidspm .Results )
27+
28+ opt.results = node.Model.Software.bidspm.Results{iRes };
29+
30+ if ~isfield(opt .results , ' montage' ) || ~opt .results .montage .do
31+ continue
32+ end
33+
34+ % set defaults
35+ [opt , ~ ] = checkMontage(opt , iRes , node , struct([]), subLabel );
36+ opt = checkOptions(opt );
37+ opt .results(iRes ).montage = setMontage(opt .results(iRes ));
38+
39+ for iName = 1 : numel(opt .results .name )
40+
41+ plotTransparentMontage(opt , SPM , subLabel , iRes , iName );
42+
43+ end
44+
14045 end
46+
47+ end
48+
14149 end
142- end
143-
50+
51+ end
52+
53+ end
54+
55+ function plotTransparentMontage(opt , SPM , subLabel , iRes , iName )
56+
57+ overwrite = true ;
58+
59+ color_map_folder = fullfile(returnRootDir(), ' lib' , ' brain_colours' , ' mat_maps' );
60+
61+ ffxDir = getFFXdir(subLabel , opt );
62+
63+ if opt .results(iRes ).binary
64+ layers = sd_config_layers(' init' , {' truecolor' , ' dual' , ' contour' });
65+ else
66+ layers = sd_config_layers(' init' , {' truecolor' , ' dual' });
67+ end
68+
69+ %% Layer 1: Anatomical map
70+ layers(1 ) = setFields(layers(1 ), opt .results(iRes ).sdConfig.layers{1 }, overwrite );
71+
72+ layers(1 ).color.file = opt .results(iRes ).montage.background{1 };
73+
74+ hdr = spm_vol(layers(1 ).color.file);
75+ [max_val , ~ ] = slover(' volmaxmin' , hdr );
76+ layers(1 ).color.range = [0 max_val ];
77+
78+ %% Layer 2: Dual-coded layer
79+
80+ % - contrast estimates color-coded;
81+ layers(2 ) = setFields(layers(2 ), opt .results(iRes ).sdConfig.layers{2 }, overwrite );
82+
83+ name = opt.results.name{iName };
84+ tmp = struct(' name' , name );
85+ contrastNb = getContrastNb(tmp , opt , SPM );
86+ % keep track if this is a t test or F test
87+ stat = SPM .xCon(contrastNb ).STAT;
88+ contrastNb = sprintf(' %04.0f ' , contrastNb );
89+
90+ % - statistics opacity-coded
91+ if strcmp(stat , ' T' )
92+ colorFile = spm_select(' FPList' , ffxDir , [' ^con_' contrastNb ' .nii$' ]);
93+ opacityFile = spm_select(' FPList' , ffxDir , [' ^spmT_' contrastNb ' .nii$' ]);
94+
95+ layers(2 ).opacity.label = ' | t |' ;
96+
97+ load(fullfile(color_map_folder , ' diverging_bwr_iso.mat' )); % #ok<*LOAD>
98+ layers(2 ).color.map = diverging_bwr ;
99+ else
100+ colorFile = spm_select(' FPList' , ffxDir , [' ^ess_' contrastNb ' .nii$' ]);
101+ opacityFile = spm_select(' FPList' , ffxDir , [' ^spmF_' contrastNb ' .nii$' ]);
102+
103+ layers(2 ).opacity.label = ' F' ;
104+
105+ load(fullfile(color_map_folder , ' 1hot_iso.mat' ));
106+ layers(2 ).color.map = hot ;
107+
108+ hdr = spm_vol(opacityFile );
109+ [max_val , ~ ] = slover(' volmaxmin' , hdr );
110+ layers(2 ).color.range = [0 max_val ];
111+
112+ layers(2 ).opacity.range = [0 5 ];
113+ end
114+ layers(2 ).color.file = colorFile ;
115+ layers(2 ).opacity.file = opacityFile ;
116+
117+ title = strrep(name , ' _' , ' ' );
118+ layers(2 ).color.label = [title ' (a.u.)' ];
119+
120+ %% Contour
121+ if opt .results(iRes ).binary
122+ layers(3 ) = setFields(layers(3 ), opt .results(iRes ).sdConfig.layers{3 }, overwrite );
123+ contour = spm_select(' FPList' , ffxDir , [' ^sub.*' contrastNb ' .*_mask.nii' ]);
124+ layers(3 ).color.file = contour ;
125+ end
126+
127+ %% Settings
128+ settings = opt .results(iRes ).sdConfig.settings;
129+
130+ % we reuse the details for the SPM montage
131+ settings.slice.disp_slices = opt .results(1 ).montage.slices;
132+ settings.slice.orientation = opt .results(1 ).montage.orientation;
133+
134+ settings.fig_specs.title = title ;
135+
136+ %% Display the layers
137+ [~ , ~ , h_figure ] = sd_display(layers , settings );
138+
139+ outputFile = fullfile(ffxDir , [contrastNb ' _' name ' .png' ]);
140+ print(h_figure , outputFile , ' -dpng' );
141+ close(h_figure );
142+
143+ % TODO
144+ % rename file
145+
144146end
0 commit comments