NeRF rendering of views. Note that it supports arbitrary batch dimensions (denoted as `...`) Args: extrinsics: (..., 4, 4) extrinsics matrice of the rendered views intrinsics (optional): (..., 3, 3) intrinsics matrice of the rendered views. width (optional): image w
(
nerf: Tensor,
extrinsics: Tensor,
intrinsics: Tensor,
width: int,
height: int,
*,
patchify: bool = False,
patch_size: Tuple[int, int] = (64, 64),
**options: Dict[str, Any]
)
| 502 | |
| 503 | |
| 504 | def nerf_render_view( |
| 505 | nerf: Tensor, |
| 506 | extrinsics: Tensor, |
| 507 | intrinsics: Tensor, |
| 508 | width: int, |
| 509 | height: int, |
| 510 | *, |
| 511 | patchify: bool = False, |
| 512 | patch_size: Tuple[int, int] = (64, 64), |
| 513 | **options: Dict[str, Any] |
| 514 | ) -> Tuple[Tensor, Tensor]: |
| 515 | """ |
| 516 | NeRF rendering of views. Note that it supports arbitrary batch dimensions (denoted as `...`) |
| 517 | |
| 518 | Args: |
| 519 | extrinsics: (..., 4, 4) extrinsics matrice of the rendered views |
| 520 | intrinsics (optional): (..., 3, 3) intrinsics matrice of the rendered views. |
| 521 | width (optional): image width of the rendered views. |
| 522 | height (optional): image height of the rendered views. |
| 523 | patchify (optional): If the image is too large, render it patch by patch |
| 524 | **options: rendering options. |
| 525 | |
| 526 | Returns: |
| 527 | rgb: (..., channels, height, width) rendered color values. |
| 528 | depth: (..., height, width) rendered depth values. |
| 529 | """ |
| 530 | if patchify: |
| 531 | # Patchified rendering |
| 532 | max_patch_width, max_patch_height = patch_size |
| 533 | n_rows, n_columns = math.ceil(height / max_patch_height), math.ceil(width / max_patch_width) |
| 534 | |
| 535 | rgb_rows, depth_rows = [], [] |
| 536 | for i_row in range(n_rows): |
| 537 | rgb_row, depth_row = [], [] |
| 538 | for i_column in range(n_columns): |
| 539 | patch_shape = patch_height, patch_width = min(max_patch_height, height - i_row * max_patch_height), min(max_patch_width, width - i_column * max_patch_width) |
| 540 | uv = image_uv(height, width, i_column * max_patch_width, i_row * max_patch_height, i_column * max_patch_width + patch_width, i_row * max_patch_height + patch_height).to(extrinsics) |
| 541 | uv = uv.flatten(0, 1) # (patch_height * patch_width, 2) |
| 542 | ray_o_, ray_d_ = get_rays(extrinsics, intrinsics, uv) |
| 543 | rgb_, depth_ = nerf_render_rays(nerf, ray_o_, ray_d_, **options, return_dict=False) |
| 544 | rgb_ = rgb_.transpose(-1, -2).unflatten(-1, patch_shape) # (..., 3, patch_height, patch_width) |
| 545 | depth_ = depth_.unflatten(-1, patch_shape) # (..., patch_height, patch_width) |
| 546 | |
| 547 | rgb_row.append(rgb_) |
| 548 | depth_row.append(depth_) |
| 549 | rgb_rows.append(torch.cat(rgb_row, dim=-1)) |
| 550 | depth_rows.append(torch.cat(depth_row, dim=-1)) |
| 551 | rgb = torch.cat(rgb_rows, dim=-2) |
| 552 | depth = torch.cat(depth_rows, dim=-2) |
| 553 | |
| 554 | return rgb, depth |
| 555 | else: |
| 556 | # Full rendering |
| 557 | uv = image_uv(height, width).to(extrinsics) |
| 558 | uv = uv.flatten(0, 1) # (height * width, 2) |
| 559 | ray_o_, ray_d_ = get_rays(extrinsics, intrinsics, uv) |
| 560 | rgb, depth = nerf_render_rays(nerf, ray_o_, ray_d_, **options, return_dict=False) |
| 561 | rgb = rgb.transpose(-1, -2).unflatten(-1, (height, width)) # (..., 3, height, width) |
nothing calls this directly
no test coverage detected