Overview #
Applying filters or other post-processing techniques to data.
Expected Output #

Prerequisite #
Tutorial #
C++
if (decFactor > 1) {
Size smallSize(depth16.cols / decFactor, depth16.rows / decFactor);
resize(depth16, depthDec, smallSize, 0, 0, INTER_NEAREST);
}
else {
depthDec = depth16.clone();
}Decimation
- Reduces resolution by an integer factor (1 = no decimation).
- Uses INTER_NEAREST to avoid interpolating fake depth values.
- Smaller resolution means less noise and faster processing.
C++
Mat depthFloat, depthSpatial;
depthDec.convertTo(depthFloat, CV_32F);
int mag = spatial_mag_slider; // 0~10
if (mag < 0) mag = 0;
int diameter = 1 + mag * 2; // 1,3,5,...,21
double sigmaCol = 10.0 + mag * 10.0;
double sigmaSpa = 10.0 + mag * 10.0;
if (mag == 0) {
depthSpatial = depthDec.clone();
}
else {
bilateralFilter(depthFloat, depthSpatial,
diameter, sigmaCol, sigmaSpa);
depthSpatial.convertTo(depthSpatial, CV_16UC1);
}- Converts depth to
floatfor more accurate filtering. - Uses bilateral filter to smooth noise while preserving edges.
- Filter strength is controlled by
mag(slider): - Larger
mag→ bigger kernel (diameter) and sigmas → stronger smoothing. - If
mag == 0, spatial filtering is effectively disabled.
C++
Mat depthTemporal16;
int tSlider = temporal_alpha_slider; // 0~10
if (tSlider <= 0) {
// No temporal filter
depthTemporal16 = depthUp;
hasTemporalPrev = false; // reset history
}
else {
float alpha = tSlider / 10.0f; // 0.1~1.0 : weight of current frame
if (!hasTemporalPrev || depthTemporalPrev16.size() != depthUp.size()) {
depthTemporalPrev16 = depthUp.clone();
hasTemporalPrev = true;
}
Mat curr32f, prev32f, out32f;
depthUp.convertTo(curr32f, CV_32F);
depthTemporalPrev16.convertTo(prev32f, CV_32F);
// out = alpha * current + (1 - alpha) * previous
out32f = alpha * curr32f + (1.0f - alpha) * prev32f;
out32f.convertTo(depthTemporal16, CV_16UC1);
depthTemporalPrev16 = depthTemporal16.clone();
}- Implements a temporal low-pass filter over consecutive frames:
- alpha close to 1 → follow new frame closely (less smoothing).
- alpha close to 0 → very smooth but more “laggy”.
- When disabled (tSlider <= 0), it bypasses the temporal filter.
- Maintains depthTemporalPrev16 as the filtered result of the previous frame
