-
Notifications
You must be signed in to change notification settings - Fork 28
/
palm_maskstruct.m
154 lines (126 loc) · 5.07 KB
/
palm_maskstruct.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
function S = palm_maskstruct(mask,readwith,extra)
% Create a struct for a mask, as if it had been read from a file.
% This is useful to save later the data.
%
% Usage:
% M = maskstruct(mask,readwith,extra)
%
% Inputs:
% mask : A (1 by m) real array.
% readwith : A string telling which function was used to read
% original data. See 'palm_miscread.m' for help.
% extra : A struct that varies according to which function
% was used to read the data.
%
% Usage:
% S : A struct derived from the 'extra' argument along
% The mask itself will then be in M.data.
%
% _____________________________________
% Anderson M. Winkler
% FMRIB / University of Oxford
% Aug/2013 (first version)
% Mar/2024 (this version)
% http://brainder.org
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% PALM -- Permutation Analysis of Linear Models
% Copyright (C) 2015 Anderson M. Winkler
%
% 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
% 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/>.
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% This is common to all cases below.
S.filename = '';
S.readwith = readwith;
% If more information is given, use to create the structs
% that will be used later to mask and save files. Note that
% the field 'filename' should remain empty.
switch lower(readwith)
case {'load','csvread','vestread'}
% If the original data is a CSV or VEST file.
S.data = mask;
S.extra = extra;
case 'wb_command'
% If the original data is CIFTI and was read after convering via
% via wb_command
S.data = mask;
S.extra = extra;
case 'cifti-matlab'
% If the original data is CIFTI and was read with
% the cifti-matlab toolbox
nD = numel(extra.diminfo);
Dlength = ones(1,nD);
for d = 1:nD
Dlength(d) = extra.diminfo{d}.length;
end
S.data = palm_conv2toN(mask,Dlength(1:end-1));
S.extra = extra;
S.extra.diminfo{end}.length = 1;
S.extra.diminfo{end}.maps = extra.diminfo{end}.maps(1);
S = palm_dimreorder(S,true);
case 'ipt'
% If the original data is NIFTI and was read with the MATLAB's
% Image Processing Toolbox or Octave's equivalent commands
S.data = palm_conv2toN(mask,extra.hdr.ImageSize(1:3));
S.extra.hdr = extra.hdr;
case 'nifticlass'
% If the original data is NIFTI and was read with the NIFTI class
S.data = palm_conv2toN(mask,extra.dat.dim(1:3));
S.extra.mat = extra.mat;
S.extra.dat.dim = extra.dat.dim;
case 'spm_spm_vol'
% If the original data is NIFTI and was read with SPM.
S.data = palm_conv2toN(mask,extra(1).dim(1:3));
S.extra = extra(1);
S.extra.dt(1) = spm_type('float64');
S.extra.pinfo(1) = 1;
case 'fs_load_nifti'
% If the original data is NIFTI and was read with FreeSurfer.
S.data = palm_conv2toN(mask,extra.hdr.dim(2:4));
S.extra = extra;
S.extra.hdr.scl_slope = 1;
S.extra.hdr.dim([1 5]) = [3 1];
S.extra.hdr.pixdim(5) = 0;
S.extra.hdr.datatype = 64;
S.extra.hdr.bitpix = 64;
case 'fsl_read_avw'
% If the original data is NIFTI and was read with FSL.
S.data = palm_conv2toN(mask,extra.dims(1:3));
S.extra = extra;
if ~ isfield(S.extra,'vtype')
S.extra.vtype = 'd';
end
case 'nii_load_nii'
% If the original data is NIFTI and was read with the NIFTI toolbox.
S.data = palm_conv2toN(mask,extra.hdr.dime.dim(2:4));
S.extra = extra;
S.extra.hdr.dime.dim([1 5]) = [3 1];
S.extra.hdr.dime.pixdim(5) = 0;
S.extra.hdr.dime.datatype = 64;
S.extra.hdr.dime.bitpix = 64;
case {'fs_read_curv','dpxread'}
% If the original data is an FS curvature.
S.data = mask;
S.extra = extra;
case 'fs_load_mgh'
% If the original data is an FS MGH/MGZ file.
S.data = palm_conv2toN(mask,extra.volsz(1:3));
S.extra = extra;
case 'gifti'
% If the original data is a GIFTI file.
S.data = mask;
S.extra = extra;
S.extra.data = S.extra.data(1);
otherwise
error('Unknown format: %s',readwith);
end