-
Notifications
You must be signed in to change notification settings - Fork 7
/
swe_getClusterStatistics.m
69 lines (55 loc) · 3.08 KB
/
swe_getClusterStatistics.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
function clusterStatistics = swe_getClusterStatistics(dataType, locationActivatedElements, dataTypeSpecificInformation, giftiAreaFile)
% Compute the cluster statitics of surviving data elements
% FORMAT clusterStatistics = swe_cifti_clusters(dataType, locationActivatedElements, dataTypeSpecificInformation, giftiAreaFile)
%
% dataType - one of the type of data defined in swe_DataType
% locationActivatedElements - an array of locations
% dataTypeSpecificInformation - a variable containing additional information specific to each type of data as described below:
% - For swe_DataType('Nifti') or swe_DataType('VolumeMat'), this variable is not used
% - For swe_DataType('Gifti') or swe_DataType('SurfaceMat'), a [mx3] faces array or a patch structure
% - For swe_DataType('Cifti'), a variable containing cifti specific information
% giftiAreaFile - the name of a GIfTI file containing the surface area of each vertex (optional and only used for swe_DataType('Gifti') or swe_DataType('SurfaceMat'))
%
% clusterStatistics - a struct containing several cluster statistics
% =========================================================================
% Bryan Guillaume
% Version Info: $Format:%ci$ $Format:%h$
clusterStatistics = struct;
if dataType == swe_DataType('Nifti') || dataType == swe_DataType('VolumeMat')
clusterStatistics.clusterAssignment = spm_clusters(locationActivatedElements);
elseif dataType == swe_DataType('Gifti') || dataType == swe_DataType('SurfaceMat')
[clusterStatistics.clusterAssignment, ~, clusterAreas] = swe_mesh_clusters(dataTypeSpecificInformation, locationActivatedElements, giftiAreaFile);
if ~isnan(clusterAreas)
clusterStatistics.clusterAreas = clusterAreas;
clusterStatistics.maxClusterArea = max(clusterStatistics.clusterAreas);
end
elseif dataType == swe_DataType('Cifti')
[clusterStatistics.clusterAssignment, ...
clusterStatistics.clusterSizesInSurfaces, ...
clusterStatistics.clusterSizesInVolume] = ...
swe_cifti_clusters(dataTypeSpecificInformation, locationActivatedElements(1,:));
if isempty(clusterStatistics.clusterSizesInSurfaces)
clusterStatistics.maxClusterSizeInSurfaces = 0;
else
clusterStatistics.maxClusterSizeInSurfaces = max(clusterStatistics.clusterSizesInSurfaces);
end
if isempty(clusterStatistics.clusterSizesInVolume)
clusterStatistics.maxClusterSizeInVolume = 0;
else
clusterStatistics.maxClusterSizeInVolume = max(clusterStatistics.clusterSizesInVolume);
end
else
error('The data type is not recognised');
end
if isnan(clusterStatistics.clusterAssignment)
clusterStatistics.clusterAssignment = [];
end
clusterStatistics.nCluster = max(clusterStatistics.clusterAssignment);
if clusterStatistics.nCluster > 0
clusterStatistics.clusterSize = histc(clusterStatistics.clusterAssignment, 1:clusterStatistics.nCluster);
clusterStatistics.maxClusterSize = max(clusterStatistics.clusterSize);
else
clusterStatistics.clusterSize = [];
clusterStatistics.maxClusterSize = 0;
end
end