-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathocclusion.cpp
51 lines (48 loc) · 2.13 KB
/
occlusion.cpp
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
/**
* @file occlusion.cpp
* @brief Detect and fill occlusions by left-right consistency
* @author Pauline Tan <[email protected]>
* Pascal Monasse <[email protected]>
*
* Copyright (c) 2012-2013, Pauline Tan, Pascal Monasse
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Pulic License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "occlusion.h"
#include "image.h"
#include <cstdlib>
/// Detect left-right discrepancies in disparity and put incoherent pixels to
/// value \a dOcclusion in \a disparityLeft.
void detect_occlusion(Image& disparityLeft, const Image& disparityRight,
float dOcclusion, int tolDisp) {
const int w=disparityLeft.width(), h=disparityLeft.height();
for(int y=0; y<h; y++)
for(int x=0; x<w; x++) {
int d = (int)disparityLeft(x,y);
if(x+d<0 || x+d>=w || abs(d+(int)disparityRight(x+d,y))>tolDisp)
disparityLeft(x,y) = dOcclusion;
}
}
/// Fill occlusions by weighted median filtering.
///
/// \param dispDense Disparity image
/// \param guidance Color guidance image, where weights are computed
/// \param disparity Values outside [dispMin,dispMax] are interpolated
/// \param dispMin,dispMax Min/max disparities
/// \param paramOcc Parameters to compute weights in bilateral filtering
void fill_occlusion(const Image& dispDense, const Image& guidance,
Image& disparity, int dispMin, int dispMax,
const ParamOcclusion& paramOcc) {
disparity = dispDense.weightedMedianColor(guidance,
disparity, dispMin, dispMax,
paramOcc.median_radius,
paramOcc.sigma_space,
paramOcc.sigma_color);
}