MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / write_depth

Function write_depth

ldm/modules/midas/utils.py:170–194  ·  view source on GitHub ↗

Write depth map to pfm and png file. Args: path (str): filepath without extension depth (array): depth

(path, depth, bits=1)

Source from the content-addressed store, hash-verified

168 return depth_resized
169
170def write_depth(path, depth, bits=1):
171 """Write depth map to pfm and png file.
172
173 Args:
174 path (str): filepath without extension
175 depth (array): depth
176 """
177 write_pfm(path + ".pfm", depth.astype(np.float32))
178
179 depth_min = depth.min()
180 depth_max = depth.max()
181
182 max_val = (2**(8*bits))-1
183
184 if depth_max - depth_min > np.finfo("float").eps:
185 out = max_val * (depth - depth_min) / (depth_max - depth_min)
186 else:
187 out = np.zeros(depth.shape, dtype=depth.type)
188
189 if bits == 1:
190 cv2.imwrite(path + ".png", out.astype("uint8"))
191 elif bits == 2:
192 cv2.imwrite(path + ".png", out.astype("uint16"))
193
194 return

Callers

nothing calls this directly

Calls 1

write_pfmFunction · 0.85

Tested by

no test coverage detected