• Docs >
  • Utils >
  • nerfacc.render_visibility_from_density
Shortcuts

nerfacc.render_visibility_from_density

nerfacc.render_visibility_from_density(t_starts, t_ends, sigmas, packed_info=None, ray_indices=None, n_rays=None, early_stop_eps=0.0001, alpha_thre=0.0, prefix_trans=None)

Compute visibility from density \(\sigma_i\) and interval \(\delta_i\).

In this function, we first compute the transmittance and opacity from the sample density. The transmittance is then used to filter out occluded samples. And opacity is used to filter out transparent samples. The function returns a boolean tensor indicating which samples are visible (transmittance > early_stop_eps and opacity > alpha_thre).

This function supports both batched and flattened input tensor. For flattened input tensor, either (packed_info) or (ray_indices and n_rays) should be provided.

Parameters:
  • alphas – The opacity values of the samples. Tensor with shape (all_samples,) or (n_rays, n_samples).

  • packed_info (Optional[Tensor]) – A tensor of shape (n_rays, 2) that specifies the start and count of each chunk in the flattened samples, with in total n_rays chunks. Useful for flattened input.

  • ray_indices (Optional[Tensor]) – Ray indices of the flattened samples. LongTensor with shape (all_samples).

  • n_rays (Optional[int]) – Number of rays. Only useful when ray_indices is provided.

  • early_stop_eps (float) – The early stopping threshold on transmittance.

  • alpha_thre (float) – The threshold on opacity.

  • prefix_trans (Optional[Tensor]) – The pre-computed transmittance of the samples. Tensor with shape (all_samples,).

  • t_starts (Tensor) –

  • t_ends (Tensor) –

  • sigmas (Tensor) –

Returns:

A boolean tensor indicating which samples are visible. Same shape as alphas.

Return type:

Tensor

Examples:

>>> t_starts = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], device="cuda")
>>> t_ends = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], device="cuda")
>>> sigmas = torch.tensor([0.4, 0.8, 0.1, 0.8, 0.1, 0.0, 0.9], device="cuda")
>>> ray_indices = torch.tensor([0, 0, 0, 1, 1, 2, 2], device="cuda")
>>> transmittance, alphas = render_transmittance_from_density(
>>>     t_starts, t_ends, sigmas, ray_indices=ray_indices)
transmittance: [1.00, 0.67, 0.30, 1.00, 0.45, 1.00, 1.00]
alphas: [0.33, 0.55, 0.095, 0.55, 0.095, 0.00, 0.59]
>>> visibility = render_visibility_from_density(
>>>     t_starts, t_ends, sigmas, ray_indices=ray_indices, early_stop_eps=0.3, alpha_thre=0.2)
tensor([True,  True, False,  True, False, False,  True])