MCPcopy Create free account
hub / github.com/Jiawei-Yang/FreeNeRF / visualize_cmap

Function visualize_cmap

internal/vis.py:56–110  ·  view source on GitHub ↗

Visualize a 1D image and a 1D weighting according to some colormap. Args: value: A 1D image. weight: A weight map, in [0, 1]. colormap: A colormap function. lo: The lower bound to use when rendering, if None then use a percentile. hi: The upper bound to use when rendering, if

(value,
                   weight,
                   colormap,
                   lo=None,
                   hi=None,
                   percentile=99.,
                   curve_fn=lambda x: x,
                   modulus=None,
                   matte_background=True)

Source from the content-addressed store, hash-verified

54
55
56def visualize_cmap(value,
57 weight,
58 colormap,
59 lo=None,
60 hi=None,
61 percentile=99.,
62 curve_fn=lambda x: x,
63 modulus=None,
64 matte_background=True):
65 """Visualize a 1D image and a 1D weighting according to some colormap.
66
67 Args:
68 value: A 1D image.
69 weight: A weight map, in [0, 1].
70 colormap: A colormap function.
71 lo: The lower bound to use when rendering, if None then use a percentile.
72 hi: The upper bound to use when rendering, if None then use a percentile.
73 percentile: What percentile of the value map to crop to when automatically
74 generating `lo` and `hi`. Depends on `weight` as well as `value'.
75 curve_fn: A curve function that gets applied to `value`, `lo`, and `hi`
76 before the rest of visualization. Good choices: x, 1/(x+eps), log(x+eps).
77 modulus: If not None, mod the normalized value by `modulus`. Use (0, 1]. If
78 `modulus` is not None, `lo`, `hi` and `percentile` will have no effect.
79 matte_background: If True, matte the image over a checkerboard.
80
81 Returns:
82 A colormap rendering.
83 """
84 # Identify the values that bound the middle of `value' according to `weight`.
85 lo_auto, hi_auto = math.weighted_percentile(
86 value, weight, [50 - percentile / 2, 50 + percentile / 2])
87
88 # If `lo` or `hi` are None, use the automatically-computed bounds above.
89 eps = jnp.finfo(jnp.float32).eps
90 lo = lo or (lo_auto - eps)
91 hi = hi or (hi_auto + eps)
92
93 # Curve all values.
94 value, lo, hi = [curve_fn(x) for x in [value, lo, hi]]
95
96 # Wrap the values around if requested.
97 if modulus:
98 value = jnp.mod(value, modulus) / modulus
99 else:
100 # Otherwise, just scale to [0, 1].
101 value = jnp.nan_to_num(
102 jnp.clip((value - jnp.minimum(lo, hi)) / jnp.abs(hi - lo), 0, 1))
103
104 if colormap:
105 colorized = colormap(value)[:, :, :3]
106 else:
107 assert len(value.shape) == 3 and value.shape[-1] == 3
108 colorized = value
109
110 return matte(colorized, weight) if matte_background else colorized
111
112
113def visualize_normals(depth, acc, scaling=None):

Callers 2

visualize_suiteFunction · 0.85
visualize_depthFunction · 0.85

Calls 1

matteFunction · 0.85

Tested by

no test coverage detected