-
Notifications
You must be signed in to change notification settings - Fork 4
/
getGLSZM_neighbor.m
55 lines (44 loc) · 1.25 KB
/
getGLSZM_neighbor.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
function GLSZM = getGLSZM_neighbor(ROIOnly,levels,neighbor)
% AUTHOR(S):
% - Lijun Lu <[email protected]>
% - Martin Vallieres <[email protected]>
% -------------------------------------------------------------------------
% HISTORY:
% - Creation: January 2013
% - Revision: May 2015
% - Revision: Oct 2017
% PRELIMINARY
nLevel = length(levels);
if nLevel > 100
adjust = 10000;
else
adjust = 1000;
end
levelTemp = max(levels) + 1;
ROIOnly(isnan(ROIOnly)) = levelTemp;
levels = [levels,levelTemp];
% QUANTIZATION EFFECTS CORRECTION
% In case (for example) we initially wanted to have 64 levels, but due to
% quantization, only 60 resulted.
uniqueVect = round(levels*adjust)/adjust;
ROIOnly = round(ROIOnly*adjust)/adjust;
NL = length(levels) - 1;
% INITIALIZATION
nInit = numel(ROIOnly);
GLSZM = zeros(NL,nInit);
% COMPUTATION OF GLSZM
temp = ROIOnly;
for i = 1:NL
temp(ROIOnly~=uniqueVect(i)) = 0;
temp(ROIOnly==uniqueVect(i)) = 1;
connObjects = bwconncomp(temp,neighbor);
nZone = length(connObjects.PixelIdxList);
for j = 1:nZone
col = length(connObjects.PixelIdxList{j});
GLSZM(i,col) = GLSZM(i,col) + 1;
end
end
% REMOVE UNECESSARY COLUMNS
stop = find(sum(GLSZM),1,'last');
GLSZM(:,(stop+1):end) = [];
end