MCPcopy Create free account
hub / github.com/CompVis/diff2flow / preprocess_depth

Function preprocess_depth

diff2flow/dataset/depth_preprocessing.py:76–112  ·  view source on GitHub ↗

Args: depth: depth map in numpy format and range [0, inf] w. shape (H, W) dataset_name: name of the dataset (e.g. vkitti2, hypersim) Returns: depth: normalized depth map with shape (C, H, W) and range [-1, 1] valid_mask: mask of valid depth values with shape

(depth, dataset_name, out_channels=3, keep_raw_depth=False)

Source from the content-addressed store, hash-verified

74
75
76def preprocess_depth(depth, dataset_name, out_channels=3, keep_raw_depth=False):
77 """
78 Args:
79 depth: depth map in numpy format and range [0, inf] w. shape (H, W)
80 dataset_name: name of the dataset (e.g. vkitti2, hypersim)
81 Returns:
82 depth: normalized depth map with shape (C, H, W) and range [-1, 1]
83 valid_mask: mask of valid depth values with shape (1, H, W)
84 """
85 # 2. calculate valid mask
86 valid_mask = calculate_valid_mask(depth, dataset_name)
87
88 # 1. cap depth to the far plane
89 depth = np.minimum(depth, MAX_FAR_PLANE)
90
91 # 3. interpolate nans
92 depth = interpolate_nans(depth)
93
94 # 4. normalize depth
95 if dataset_name == 'hypersim':
96 depth = distance_to_planar_depth(depth)
97
98 if keep_raw_depth:
99 depth = depth[None].repeat(out_channels, axis=0)
100 return depth, valid_mask
101
102 q_min, q_max = np.percentile(depth, (1, 99))
103 q_min = np.log(q_min)
104 q_max = np.log(q_max)
105 depth = np.log(depth)
106 depth = (depth - q_min) / (q_max - q_min)
107 depth = (depth - 0.5) * 2
108
109 # 5. add channel dimension
110 depth = depth[None].repeat(out_channels, axis=0)
111
112 return depth, valid_mask
113
114
115class DatasetPreprocessor:

Callers 1

preprocess_sampleMethod · 0.85

Calls 3

calculate_valid_maskFunction · 0.85
interpolate_nansFunction · 0.85
distance_to_planar_depthFunction · 0.85

Tested by

no test coverage detected