forked from andersonwinkler/PALM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalm_maskstruct.m
More file actions
128 lines (105 loc) · 4.19 KB
/
palm_maskstruct.m
File metadata and controls
128 lines (105 loc) · 4.19 KB
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
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 '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
% 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',
S.data = mask;
S.extra = extra;
case 'nifticlass',
% If the original data is NIFTI and was read witht the NIFTI class
S.data = palm_conv2to4(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_conv2to4(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_conv2to4(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_conv2to4(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_conv2to4(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_conv2to4(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.')
end