-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsurf_makeLabelGifti.m
68 lines (63 loc) · 2.18 KB
/
surf_makeLabelGifti.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
function G=surf_makeLabelGifti(data,varargin)
% function G=surf_makeLabelGifti(data,varargin)
% Builds a Label GIFTI structure from scratch for saving
%
% INPUT:
% data: N x Q data matrix: N:number of nodes, Q: number of data series
%
% VARARGIN:
% 'anatomicalStruct': Anatomical Structure for header
% 'CortexLeft','CortexRight','Cerebellum'
% 'labelNames': Cell array of Names for the labels
% 'columnNames': Cell array of the Names of different data columns
% 'labelRGBA': numLabel x 4 matrix of RGB + alpha (opacacity) values
%
% OUTPUT:
% G: Gifti object - save with save(G,'filename')
% ---------------------------------------------------------------------------------
anatomicalStruct = 'CortexLeft';
columnNames = {};
labelRGBA = [];
keys = unique(data)';
labelNames = {};
vararginoptions(varargin,{'anatomicalStruct','columnNames','labelNames', 'keys', 'labelRGBA'});
[N,Q] = size(data);
% keys = unique(data)';
nLabel = length(keys); % number of unique labels
% Create naming and coloring if not given:
% 1) Make column_names if empty
if (isempty(columnNames))
for i=1:nLabel
columnNames{i}=sprintf('col_%d',i);
end
end
% 2) Determine color scale if empty
if (isempty(labelRGBA))
col = hsv(nLabel);
col = col(randperm(nLabel),:); % shuffle the order so it's more visible
labelRGBA = zeros(nLabel,4);
for i=1:nLabel
labelRGBA(i,:)=[col(i,:) 1];
end
end
% 3) Give label names
if (isempty(labelNames))
for i=1:nLabel
labelNames{i}=sprintf('label-%d',i);
end
end
% Create the label.gii structure
this.metadata(1) = struct('name','AnatomicalStructurePrimary','value',anatomicalStruct);
this.metadata(2) = struct('name','encoding','value','XML_BASE64_GZIP');
this.label.name = labelNames;
this.label.key = keys;
this.label.rgba = labelRGBA;
for i=1:Q
this.data{i}.data=int32(data(:,i));
this.data{i}.metadata(1) = struct('name','Name','value',columnNames{i});
this.data{i}.attributes.Dim=N;
this.data{i}.attributes.DataType = 'NIFTI_TYPE_INT32';
this.data{i}.attributes.Intent = 'NIFTI_INTENT_LABEL';
this.data{i}.space=[];
end;
G=gifti(this);