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)
| 216 | |
| 217 | |
| 218 | def 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 | |
| 232 | def read_meta(path: Union[str, os.PathLike, IO]) -> Dict[str, Any]: |
nothing calls this directly
no outgoing calls
no test coverage detected