forked from egeyosunkaya/ImageAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculateGradientEdgeCost.m
52 lines (43 loc) · 1.35 KB
/
calculateGradientEdgeCost.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
function [edgeResponse, commonSize] = calculateGradientEdgeCost(edgeImg, labels,labelIndices, labOne, labTwo)
edgeResponse = 0;
commonSize = 0;
% Find common border..
[rC,cC] = size(labels);
temp = labelIndices{1,labOne};
rowArr = temp(:,1);
colArr = temp(:,2);
[realSize,~] = size(rowArr);
totalResp = 0;
commonSize = 0;
for i=1:realSize
xCor = rowArr(i,1);
yCor = colArr(i,1);
if xCor + 1 <= rC
if labels(xCor+1,yCor) == labTwo % Common border!
commonSize = commonSize + 1;
totalResp = totalResp + abs(edgeImg(xCor,yCor)-edgeImg(xCor+1,yCor));
end
end
if xCor - 1 > 0
if labels(xCor-1,yCor) == labTwo % Common border!
commonSize = commonSize + 1;
totalResp = totalResp + abs(edgeImg(xCor,yCor) - edgeImg(xCor-1,yCor));
end
end
if yCor + 1 <= cC
if labels(xCor,yCor+1) == labTwo % Common border!
commonSize = commonSize + 1;
totalResp = totalResp + abs(edgeImg(xCor,yCor) - edgeImg(xCor,yCor+1));
end
end
if yCor - 1 > 0
if labels(xCor,yCor-1) == labTwo % Common border!
commonSize = commonSize + 1;
totalResp = totalResp + abs(edgeImg(xCor,yCor-1)-edgeImg(xCor,yCor) );
end
end
end
if commonSize ~=0
edgeResponse = totalResp / commonSize;
end
end