LiDAR-Perfect-Depth / code /ppd /utils /vis_utils.py
chenming-wu's picture
code
436b829 verified
import numpy as np
import matplotlib
import torch
def visualize_depth(depth: np.ndarray,
depth_min=None,
depth_max=None,
percentile=2,
ret_minmax=False,
cmap='Spectral'):
if depth_min is None: depth_min = np.percentile(depth, percentile)
if depth_max is None: depth_max = np.percentile(depth, 100 - percentile)
if depth_min == depth_max:
depth_min = depth_min - 1e-6
depth_max = depth_max + 1e-6
cm = matplotlib.colormaps[cmap]
depth = ((depth - depth_min) / (depth_max - depth_min)).clip(0, 1)
img_colored_np = cm(depth, bytes=False)[:, :, 0:3] # value from 0 to 1
if ret_minmax:
return img_colored_np, depth_min, depth_max
else:
return img_colored_np