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)
| 7 | |
| 8 | |
| 9 | def 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 | |
| 29 | def interpolate_nans(array, fill_values=1e-4): |