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

Function write_normal

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

Write a normal image, input float32 normal array of shape (H, W, 3).

(path: Union[str, os.PathLike, IO], normal: np.ndarray, compression_level: int = 7)

Source from the content-addressed store, hash-verified

216
217
218def write_normal(path: Union[str, os.PathLike, IO], normal: np.ndarray, compression_level: int = 7) -> np.ndarray:
219 """
220 Write a normal image, input float32 normal array of shape (H, W, 3).
221 """
222 mask_nan = np.isnan(normal).any(axis=-1)
223 normal = ((normal * [0.5, -0.5, -0.5] + 0.5).clip(0, 1) * 65535).astype(np.uint16)
224 normal[mask_nan] = 0
225 data = cv2.imencode('.png', cv2.cvtColor(normal, cv2.COLOR_RGB2BGR), [cv2.IMWRITE_PNG_COMPRESSION, compression_level])[1].tobytes()
226 if isinstance(path, (str, os.PathLike)):
227 Path(path).write_bytes(data)
228 else:
229 path.write(data)
230
231
232def read_meta(path: Union[str, os.PathLike, IO]) -> Dict[str, Any]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected