-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSGM_postprocessing.m
62 lines (54 loc) · 1.85 KB
/
SGM_postprocessing.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
function [Db_final] = SGM_postprocessing(Db, Dm)
%input:
% Db: disparity image using base image as left image
% Dm: disparity image using match image as left image
%return:
% Db_final: final disparity image after postprocessing
%factor = 4;
[H,W] = size(Db);
%true occlusion and Db
% occlusion_true = double(imread('E:\cones\occl.png'));
% Db_true = double(imread('E:\cones\disp2.png')/factor);
%%LR check
invalid_map = ones(H,W);%0(black) denotes invalid pixel(mismatched or occluded)
occlusion_map = ones(H,W);
mismatched_map = ones(H,W);
for i = 1:H
for j = 1:W
Dbp = Db(i,j);
Dmq = Dm(i,j-Dbp);
if abs(Dbp-Dmq)>1
invalid_map(i,j)=0;
if Db(i,j-Dbp+Dmq)>Dbp
occlusion_map(i,j)=0;
else
mismatched_map(i,j)=0;
end
end
end
end
%imshow(invalid_map);
Db_rec = Db.*invalid_map;
% imshow(uint8(factor*Db_rec));
% [bad1, bad2, bad4, rmse] = SGM_eval(Db_rec, Db_true.*occlusion_true); %evaluate
%%invalid(mismatched and occluded) region filling
Db_fill = Db_rec;
for i = 1:H
for j = 1:W
if Db_rec(i,j)==0
if occlusion_map(i,j)==0
Db_fill(i,j) = round(SGM_filling_search(i,j,Db_fill,'occluded'));
else
Db_fill(i,j) = round(SGM_filling_search(i,j,Db_fill,'mismatched'));
end
end
end
end
%imshow(uint8(factor*Db_fill));
%[bad1, bad2, bad4, rmse] = SGM_eval(Db_fill, Db_true); %evaluate
%%median filtering
Db_final = round(medfilt2(Db_fill,[5 5],'symmetric'));
% imshow(uint8(factor*Db_final));
% [bad1, bad2, bad4, rmse] = SGM_eval(Db_final, Db_true); %evaluate
%[bad1, bad2, bad4, rmse] = SGM_eval(Db_final.*occlusion_map, Db_true.*occlusion_true)
end