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

Function distance_to_planar_depth

diff2flow/dataset/depth_preprocessing.py:9–26  ·  view source on GitHub ↗

Convert distance to focal point to planar depth. Adapted from https://github.com/apple/ml-hypersim/issues/9#issuecomment-754935697 Args: distance: distance to focal point (depth_meters.hdf5), shape (h, w) focal_length: focal length of camera height, width: heigh

(distance, focal_length: float = 886.81, height: int = 768, width: int = 1024)

Source from the content-addressed store, hash-verified

7
8
9def distance_to_planar_depth(distance, focal_length: float = 886.81, height: int = 768, width: int = 1024):
10 """
11 Convert distance to focal point to planar depth. Adapted from
12 https://github.com/apple/ml-hypersim/issues/9#issuecomment-754935697
13
14 Args:
15 distance: distance to focal point (depth_meters.hdf5), shape (h, w)
16 focal_length: focal length of camera
17 height, width: height and width of image
18 Returns:
19 planar_depth: planar depth, shape (h, w)
20 """
21 npyImageplaneX = np.linspace((-0.5 * width) + 0.5, (0.5 * width) - 0.5, width).reshape(1, width).repeat(height, 0).astype(np.float32)[:, :, None]
22 npyImageplaneY = np.linspace((-0.5 * height) + 0.5, (0.5 * height) - 0.5, height).reshape(height, 1).repeat(width, 1).astype(np.float32)[:, :, None]
23 npyImageplaneZ = np.full([height, width, 1], focal_length, np.float32)
24 npyImageplane = np.concatenate([npyImageplaneX, npyImageplaneY, npyImageplaneZ], 2)
25 planar_depth = distance / np.linalg.norm(npyImageplane, 2, 2) * focal_length
26 return planar_depth
27
28
29def interpolate_nans(array, fill_values=1e-4):

Callers 1

preprocess_depthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected