Files
nerfstudio/docs/notebooks/visualize_samples.ipynb
T
Matthew Tancik 6050dfb6e3 Update to myst_nb (#206)
* Update to myst_nb

* Fix action

* Remove action for now
2022-07-25 19:22:39 -07:00

6.8 MiB

Sample Representation

A core component of volumetric rendering is computing samples along a ray. The representation of these samples is important. We use conical frustums to represent samples. The conical frustums are defined via the following parameters:

Frustums Diagram
Parameter Dimension Description
origin 3 The x,y,z origin of the ray
direction 3 The direction of the ray represented as a unit vector
pixel area 1 The pixel's area a distance of 1 from the origin
start 1 The distance at which the frustum starts
end 1 The distance at which the frustums ends

:::{note} Why conical frustums and not pyramidal frustums? Those interested in this question may be interested in A Pixel Is Not A Little Square by Alvy Ray Smith. :::

:::{important} This representation is only an approximation. Nerfacory calculates pixel area as dx * dy where dx and dy are the distance between points neighboring rays in the x and y direction a distance of 1 from the origin. :::

3D Frustum Visualization

In [2]:
# COLLAPSED
import torch
from nerfactory.cameras import cameras
from nerfactory.utils import plotly as vis
import plotly.graph_objects as go

cx = 2
cy = 2
fx = 10
fy = 10

num_samples = 3
near_plane = 1
far_plane = 3

camera = cameras.PinholeCamera(cx, cy, fx, fy)
ray_bundle = camera.get_camera_ray_bundle()

bins = torch.linspace(near_plane, far_plane, num_samples + 1)[..., None]
ray_samples = ray_bundle.get_ray_samples(bin_starts=bins[:-1, :], bin_ends=bins[1:, :])

vis_rays = vis.get_ray_bundle_lines(ray_bundle, color="teal", length=far_plane)

fig = go.Figure(
    data=[vis_rays] + vis.get_frustums_mesh_list(ray_samples.frustums),
    layout=go.Layout(scene_camera=dict(up=dict(x=0, y=1, z=0)), title="Frustums"),
)
fig.show()
fig.write_html("frustums.html")

Representing Frustums as Points

These frustums can be converted into point samples using frustum.get_positions().

In [3]:
# COLLAPSED
fig = go.Figure(
    data=[vis_rays, vis.get_frustum_points(ray_samples.frustums)],
    layout=go.Layout(scene_camera=dict(up=dict(x=0, y=1, z=0)), title="Frustums as Points"),
)
fig.show()

Representing Frustums as Gaussians

We can also appoximate the frustums using Gaussians with frustum.get_gaussian_blob().

In [4]:
# COLLAPSED
fig = go.Figure(
    data=[vis_rays] + vis.get_gaussian_ellipsoids_list(ray_samples.frustums.flatten().get_gaussian_blob()),
    layout=go.Layout(scene_camera=dict(up=dict(x=0, y=1, z=0)), title="Frustums as Gaussians"),
)
fig.show()