mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-12-07 00:09:14 +08:00
Add disparity maps
This commit is contained in:
1 parent
0b82c1188c
commit
2268a9152b
3 files changed
+50
-1
No files matched your search
@@ -16,6 +16,7 @@ class RendererOutputs:
|
||||
rgb: TensorType["num_rays", 3] = None
|
||||
density: TensorType["num_rays", 1] = None
|
||||
accumulation: TensorType["num_rays", 1] = None
|
||||
disparity: TensorType["num_rays", 1] = None
|
||||
|
||||
|
||||
class RGBRenderer(nn.Module):
|
||||
@@ -79,3 +80,37 @@ class AccumulationRenderer(nn.Module):
|
||||
|
||||
renderer_outputs = RendererOutputs(accumulation=accumulation)
|
||||
return renderer_outputs
|
||||
|
||||
|
||||
class DisparityRenderer(nn.Module):
|
||||
"""Calcualte depth along ray."""
|
||||
|
||||
def __init__(self, method: str = "expected") -> None:
|
||||
"""
|
||||
Args:
|
||||
method (str, optional): Depth calculation method. Defaults to 'expected'.
|
||||
"""
|
||||
super().__init__()
|
||||
if method not in {"expected"}:
|
||||
raise ValueError(f"{method} is an invalid depth calculation method")
|
||||
self.method = method
|
||||
|
||||
def forward(self, weights: TensorType[..., "num_samples"], ts: TensorType[..., "num_samples"]) -> RendererOutputs:
|
||||
"""Composite samples along ray and calculate disparities.
|
||||
|
||||
Args:
|
||||
weights (TensorType[..., "num_samples"]): Weights for each sample
|
||||
ts (TensorType[..., "num_samples"]): Sample locations along rays
|
||||
|
||||
Returns:
|
||||
RendererOutputs: Outputs with disparity values.
|
||||
"""
|
||||
|
||||
if self.method == "expected":
|
||||
depth = torch.sum(weights * ts, dim=-1)
|
||||
eps = 1e-10
|
||||
disparity = 1.0 / torch.max(eps * torch.ones_like(depth), depth / torch.sum(weights, -1))
|
||||
|
||||
return RendererOutputs(disparity=disparity)
|
||||
|
||||
raise NotImplementedError(f"Method {self.method} not implemented")
|
||||
Reference in new issue
Block a user