forked from NISOx-BDI/SwE-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swe_cifti_clusters.m
71 lines (69 loc) · 3.31 KB
/
swe_cifti_clusters.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
function [A, clusterSizesInSurfaces, clusterSizesInVolume] = swe_cifti_clusters(ciftiInformation, indSurvivingInCifti)
% Compute the clusters for CIfTI data
% FORMAT A = swe_cifti_clusters(ciftiInformation, indSurvivingInCifti)
% ciftiInformation - cifti information
% indSurvivingInCifti - an array of locations {in cifti indices}
% A - a vector of cluster indices
% =========================================================================
% Bryan Guillaume
% Version Info: $Format:%ci$ $Format:%h$
A = zeros(1, numel(indSurvivingInCifti));
clusterSizesInSurfaces = [];
clusterSizesInVolume = [];
% for retro-compatibility
if isfield(ciftiInformation, 'isClusConstrainedInVolROI')
isClusConstrainedInVolROI = ciftiInformation.isClusConstrainedInVolROI;
else
isClusConstrainedInVolROI = false;
end
if numel(ciftiInformation.surfaces) > 0
for i = 1:numel(ciftiInformation.surfaces)
% work out the position of the surviving vertices for this surface
indInSurface = ciftiInformation.surfaces{i}.off + (1:numel(ciftiInformation.surfaces{i}.iV));
[isSurviving, indInA] = ismember(indInSurface, indSurvivingInCifti);
indInA = indInA(isSurviving);
indSurvivingInSurface = ciftiInformation.surfaces{i}.iV(isSurviving);
T = false(ciftiInformation.surfaces{i}.nV, 1);
T(indSurvivingInSurface) = true;
G = export(gifti(ciftiInformation.surfaces{i}.geomFile), 'patch');
tmp = spm_mesh_clusters(G,T)';
tmp = tmp(indSurvivingInSurface);
A(indInA) = tmp + max(A);
nClusters = max(tmp);
if isfield(ciftiInformation.surfaces{i}, 'areaFile')
area = swe_data_read(ciftiInformation.surfaces{i}.areaFile, indSurvivingInSurface);
clusterSizesInThisSurface = zeros(1, nClusters);
for iCluster = 1:nClusters
clusterSizesInThisSurface(iCluster) = sum(area(tmp == iCluster));
end
clusterSizesInSurfaces = [clusterSizesInSurfaces, clusterSizesInThisSurface];
else
clusterSizesInSurfaces = [clusterSizesInSurfaces, histc(tmp,1:nClusters)];
end
end
end
% deal with volumetric data
if ~isClusConstrainedInVolROI && numel(ciftiInformation.volume) > 0
% work out the position of the surviving voxels
[isSurviving, indInA] = ismember(ciftiInformation.volume.indices, indSurvivingInCifti);
indInA = indInA(isSurviving);
inMask_vol_XYZ = ciftiInformation.volume.XYZ(:, isSurviving);
tmp = spm_clusters(inMask_vol_XYZ);
A(indInA) = tmp + max(A);
nClusters = max(tmp);
clusterSizesInVolume = histc(tmp,1:nClusters);
end
if isClusConstrainedInVolROI && isfield(ciftiInformation, 'volumes') && numel(ciftiInformation.volumes) > 0
for i = 1:numel(ciftiInformation.volumes)
% work out the position of the surviving voxels
indicesVolInCifti = (ciftiInformation.volumes{i}.off + 1):(ciftiInformation.volumes{i}.off + size(ciftiInformation.volumes{i}.iV, 2));
[isSurviving, indInA] = ismember(indicesVolInCifti, indSurvivingInCifti);
indInA = indInA(isSurviving);
inMask_vol_XYZ = ciftiInformation.volumes{i}.iV(:, isSurviving);
tmp = spm_clusters(inMask_vol_XYZ);
A(indInA) = tmp + max(A);
nClusters = max(tmp);
clusterSizesInVolume = [clusterSizesInVolume, histc(tmp,1:nClusters)];
end
end
end