MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / read_depth

Function read_depth

eval_code/recons/models/moge/utils/io.py:89–107  ·  view source on GitHub ↗

Read a depth image, return float32 depth array of shape (H, W).

(path: Union[str, os.PathLike, IO])

Source from the content-addressed store, hash-verified

87
88
89def read_depth(path: Union[str, os.PathLike, IO]) -> Tuple[np.ndarray, float]:
90 """
91 Read a depth image, return float32 depth array of shape (H, W).
92 """
93 if isinstance(path, (str, os.PathLike)):
94 data = Path(path).read_bytes()
95 else:
96 data = path.read()
97 pil_image = Image.open(io.BytesIO(data))
98 near = float(pil_image.info.get('near'))
99 far = float(pil_image.info.get('far'))
100 unit = float(pil_image.info.get('unit')) if 'unit' in pil_image.info else None
101 depth = np.array(pil_image)
102 mask_nan, mask_inf = depth == 0, depth == 65535
103 depth = (depth.astype(np.float32) - 1) / 65533
104 depth = near ** (1 - depth) * far ** depth
105 depth[mask_nan] = np.nan
106 depth[mask_inf] = np.inf
107 return depth, unit
108
109
110def write_depth(

Callers

nothing calls this directly

Calls 3

readMethod · 0.80
openMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected