-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculateEdgeCost.m
61 lines (51 loc) · 1.53 KB
/
calculateEdgeCost.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
function [edgeResponse, commonSize] = calculateEdgeCost(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;
if edgeImg(xCor,yCor) ~= edgeImg(xCor+1,yCor)
totalResp = totalResp + 1;
end
end
end
if xCor - 1 > 0
if labels(xCor-1,yCor) == labTwo % Common border!
commonSize = commonSize + 1;
if edgeImg(xCor,yCor) ~= edgeImg(xCor-1,yCor)
totalResp = totalResp + 1;
end
end
end
if yCor + 1 <= cC
if labels(xCor,yCor+1) == labTwo % Common border!
commonSize = commonSize + 1;
if edgeImg(xCor,yCor) ~= edgeImg(xCor,yCor+1)
totalResp = totalResp + 1;
end
end
end
if yCor - 1 > 0
if labels(xCor,yCor-1) == labTwo % Common border!
commonSize = commonSize + 1;
if edgeImg(xCor,yCor) ~= edgeImg(xCor,yCor-1)
totalResp = totalResp + 1;
end
end
end
end
if commonSize ~=0
edgeResponse = totalResp / commonSize;
end
end