-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfill_depth_cross_bf.m
51 lines (44 loc) · 1.8 KB
/
fill_depth_cross_bf.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
% In-paints the depth image using a cross-bilateral filter. The operation
% is implemented via several filterings at various scales. The number of
% scales is determined by the number of spacial and range sigmas provided.
% 3 spacial/range sigmas translated into filtering at 3 scales.
%
% Args:
% imgRgb - the RGB image, a uint8 HxWx3 matrix
% imgDepthAbs - the absolute depth map, a HxW double matrix whose values
% indicate depth in meters.
% spaceSigmas - (optional) sigmas for the spacial gaussian term.
% rangeSigmas - (optional) sigmas for the intensity gaussian term.
%
% Returns:
% imgDepthAbs - the inpainted depth image.
function imgDepthAbs = fill_depth_cross_bf(imgRgb, imgDepthAbs, ...
spaceSigmas, rangeSigmas)
error(nargchk(2,4,nargin));
assert(isa(imgRgb, 'uint8'), 'imgRgb must be uint8');
assert(isa(imgDepthAbs, 'double'), 'imgDepthAbs must be a double');
if nargin < 3
spaceSigmas = [12 5 8];
end
if nargin < 4
rangeSigmas = [0.2 0.08 0.02];
end
assert(numel(spaceSigmas) == numel(rangeSigmas));
assert(isa(rangeSigmas, 'double'));
assert(isa(spaceSigmas, 'double'));
% Create the 'noise' image and get the maximum observed depth.
imgIsNoise = imgDepthAbs == 0 | imgDepthAbs == 10;
maxDepthObs = max(imgDepthAbs(~imgIsNoise));
% Convert the depth image to uint8.
imgDepth = imgDepthAbs ./ maxDepthObs;
imgDepth(imgDepth > 1) = 1;
imgDepth = uint8(imgDepth * 255);
% Run the cross-bilateral filter.
if ispc
imgDepthAbs = mex_cbf_windows(imgDepth, rgb2gray(imgRgb), imgIsNoise, spaceSigmas(:), rangeSigmas(:));
else
imgDepthAbs = mex_cbf(imgDepth, rgb2gray(imgRgb), imgIsNoise, spaceSigmas(:), rangeSigmas(:));
end
% Convert back to absolute depth (meters).
imgDepthAbs = im2double(imgDepthAbs) .* maxDepthObs;
end