(depth, fpath="raw.png")
| 356 | return ToTensor()(img).unsqueeze(0) |
| 357 | |
| 358 | def save_raw_16bit(depth, fpath="raw.png"): |
| 359 | if isinstance(depth, torch.Tensor): |
| 360 | depth = depth.squeeze().cpu().numpy() |
| 361 | |
| 362 | assert isinstance(depth, np.ndarray), "Depth must be a torch tensor or numpy array" |
| 363 | assert depth.ndim == 2, "Depth must be 2D" |
| 364 | depth = depth * 256 # scale for 16-bit png |
| 365 | depth = depth.astype(np.uint16) |
| 366 | depth = Image.fromarray(depth) |
| 367 | depth.save(fpath) |
| 368 | print("Saved raw depth to", fpath) |