-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSGM_filling_search.m
102 lines (98 loc) · 1.77 KB
/
SGM_filling_search.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function [value] = SGM_filling_search(m, n, Db, invalid_type)
%start from position(m,n), collect first valid disparity along 8
%different paths, return second lowest value
[H,W] = size(Db);
vec = zeros(8,1);
threshold = 1;
%to left
for j = n-1:-1:1
if Db(m,j)>threshold
vec(1) = Db(m,j);
break;
end
end
%to right
for j = n+1:W
if Db(m,j)>threshold
vec(2) = Db(m,j);
break;
end
end
%to bottom
for i = m+1:H
if Db(i,n)>threshold
vec(3) = Db(i,n);
break;
end
end
%to top
for i = m-1:-1:1
if Db(i,n)>threshold
vec(4) = Db(i,n);
break;
end
end
%to left top
falg = 0;
for i = m-1:-1:1
for j = n-1:-1:1
if Db(i,j)>threshold
vec(5) = Db(i,j);
flag = 1;
break;
end
end
if falg == 0
break;
end
end
%to right bottom
flag = 0;
for i = m+1:H
for j = n+1:W
if Db(i,j)>threshold
vec(6) = Db(i,j);
flag = 1;
break;
end
end
if flag == 1
break;
end
end
%to left bottom
flag = 0;
for i = m+1:H
for j = n-1:-1:1
if Db(i,j)>threshold
vec(7) = Db(i,j);
flag = 1;
break;
end
end
if flag == 1
break;
end
end
%to right top
flag = 0;
for i = m-1:-1:1
for j = n+1:W
if Db(i,j)>threshold
vec(8) = Db(i,j);
flag = 1;
break;
end
end
if flag == 1
break;
end
end
if strcmp(invalid_type, 'occluded')
value = vec(2);
elseif strcmp(invalid_type, 'mismatched')
value = median(vec);
if value<=0
value = max(vec);
end
end