Math#

Math Helper Functions

class nerfstudio.utils.math.Gaussians(mean: Tensor, cov: Tensor)#

Bases: object

Stores Gaussians

Parameters:
  • mean – Mean of multivariate Gaussian

  • cov – Covariance of multivariate Gaussian.

nerfstudio.utils.math.components_from_spherical_harmonics(levels: int, directions: Tensor) Tensor#

Returns value for each component of spherical harmonics.

Parameters:
  • levels – Number of spherical harmonic levels to compute.

  • directions – Spherical harmonic coefficients

nerfstudio.utils.math.compute_3d_gaussian(directions: Tensor, means: Tensor, dir_variance: Tensor, radius_variance: Tensor) Gaussians#

Compute gaussian along ray.

Parameters:
  • directions – Axis of Gaussian.

  • means – Mean of Gaussian.

  • dir_variance – Variance along direction axis.

  • radius_variance – Variance tangent to direction axis.

Returns:

Oriented 3D gaussian.

Return type:

Gaussians

nerfstudio.utils.math.conical_frustum_to_gaussian(origins: Tensor, directions: Tensor, starts: Tensor, ends: Tensor, radius: Tensor) Gaussians#

Approximates conical frustums with a Gaussian distributions.

Uses stable parameterization described in mip-NeRF publication.

Parameters:
  • origins – Origins of cones.

  • directions – Direction (axis) of frustums.

  • starts – Start of conical frustums.

  • ends – End of conical frustums.

  • radius – Radii of cone a distance of 1 from the origin.

Returns:

Approximation of conical frustums

Return type:

Gaussians

nerfstudio.utils.math.cylinder_to_gaussian(origins: Tensor, directions: Tensor, starts: Tensor, ends: Tensor, radius: Tensor) Gaussians#

Approximates cylinders with a Gaussian distributions.

Parameters:
  • origins – Origins of cylinders.

  • directions – Direction (axis) of cylinders.

  • starts – Start of cylinders.

  • ends – End of cylinders.

  • radius – Radii of cylinders.

Returns:

Approximation of cylinders

Return type:

Gaussians

nerfstudio.utils.math.expected_sin(x_means: Tensor, x_vars: Tensor) Tensor#

Computes the expected value of sin(y) where y ~ N(x_means, x_vars)

Parameters:
  • x_means – Mean values.

  • x_vars – Variance of values.

Returns:

The expected value of sin.

Return type:

torch.Tensor

nerfstudio.utils.math.intersect_aabb(origins: Tensor, directions: Tensor, aabb: Tensor) Tuple[Tensor, Tensor]#

Implementation of ray intersection with AABB box

Parameters:
  • origins – 3d positions

  • directions – Normalized directions

  • aabb – array of aabb box in the form of [x_min, y_min, z_min, x_max, y_max, z_max]

  • max_bound – Maximum value of t_max

  • invalid_value – Value to return in case of no intersection

Returns:

t_min, t_max - two tensors of shapes N representing distance of intersection from the origin.

nerfstudio.utils.math.masked_reduction(input_tensor: Tensor, mask: Tensor, reduction_type: Literal['image', 'batch'])#

Whether to consolidate the input_tensor across the batch or across the image :param input_tensor: input tensor :param mask: mask tensor :param reduction_type: either “batch” or “image”

Returns:

reduced input_tensor

Return type:

input_tensor

nerfstudio.utils.math.normalized_depth_scale_and_shift(prediction: Tensor, target: Tensor, mask: Tensor)#

More info here: https://arxiv.org/pdf/2206.00665.pdf supplementary section A2 Depth Consistency Loss This function computes scale/shift required to normalizes predicted depth map, to allow for using normalized depth maps as input from monocular depth estimation networks. These networks are trained such that they predict normalized depth maps.

Solves for scale/shift using a least squares approach with a closed form solution: Based on: https://github.com/autonomousvision/monosdf/blob/d9619e948bf3d85c6adec1a643f679e2e8e84d4b/code/model/loss.py#L7 :param prediction: predicted depth map :param target: ground truth depth map :param mask: mask of valid pixels

Returns:

scale and shift for depth prediction

nerfstudio.utils.math.safe_normalize(vectors: Tensor, eps: float = 1e-10) Tensor#

Normalizes vectors.

Parameters:
  • vectors – Vectors to normalize.

  • eps – Epsilon value to avoid division by zero.

Returns:

Normalized vectors.