Shortcuts

nerfacc.render_visibility

nerfacc.render_visibility(alphas, *, ray_indices=None, packed_info=None, n_rays=None, early_stop_eps=0.0001, alpha_thre=0.0)

Filter out transparent and occluded samples.

In this function, we first compute the transmittance from the sample opacity. 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).

Note

Either ray_indices or packed_info should be provided. If ray_indices is provided, CUB acceleration will be used if available (CUDA >= 11.6). Otherwise, we will use the naive implementation with packed_info.

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

  • packed_info (Optional[Tensor]) – Optional. Stores information on which samples belong to the same ray. See nerfacc.ray_marching() for details. LongTensor with shape (n_rays, 2).

  • ray_indices (Optional[Tensor]) – Optional. Ray index of each sample. LongTensor with shape (n_sample).

  • n_rays (Optional[int]) – Optional. Number of rays. Only useful when ray_indices is provided yet CUB acceleration is not available. We will implicitly convert ray_indices to packed_info and use the naive implementation. If not provided, we will infer it from ray_indices but it will be slower.

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

  • alpha_thre (float) – The threshold on opacity.

Returns:

The visibility of each sample. Tensor with shape (n_samples, 1).

Return type:

Tensor

Examples:

>>> alphas = 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 = render_transmittance_from_alpha(alphas, ray_indices=ray_indices)
tensor([[1.0], [0.6], [0.12], [1.0], [0.2], [1.0], [1.0]])
>>> visibility = render_visibility(
>>>     alphas, ray_indices=ray_indices, early_stop_eps=0.3, alpha_thre=0.2)
tensor([True,  True, False,  True, False, False,  True])