Skip to content

Commit 5e02aa4

Browse files
authored
Merge pull request #51 from probcomp/debug_with_eric
WTF
2 parents ec3368c + 208a68d commit 5e02aa4

File tree

2 files changed

+350
-18
lines changed

2 files changed

+350
-18
lines changed

bayes3d/viz/viz.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ def preprocess_for_viz(img):
4545
return depth_np
4646

4747

48-
cmap = copy.copy(plt.get_cmap("turbo"))
48+
cmap = copy.copy(plt.get_cmap('turbo'))
4949
cmap.set_bad(color=(1.0, 1.0, 1.0, 1.0))
5050

51-
52-
def get_depth_image(image, min_val=None, max_val=None, remove_max=True):
51+
def get_depth_image(image, max=None):
5352
"""Convert a depth image to a PIL image.
54-
53+
5554
Args:
5655
image (np.ndarray): Depth image. Shape (H, W).
5756
min (float): Minimum depth value for colormap.
@@ -60,28 +59,22 @@ def get_depth_image(image, min_val=None, max_val=None, remove_max=True):
6059
Returns:
6160
PIL.Image: Depth image visualized as a PIL image.
6261
"""
63-
if len(image.shape) > 2:
64-
depth = np.array(image[:, :, -1])
62+
depth = np.array(image)
63+
if max is None:
64+
maxim = depth.max()
6565
else:
66-
depth = np.array(image)
67-
68-
if max_val is None:
69-
max_val = depth.max()
70-
if not remove_max:
71-
max_val += 1
72-
if min_val is None:
73-
min_val = depth.min()
74-
75-
mask = (depth < max_val) * (depth > min_val)
66+
maxim = max
67+
mask = depth < maxim
7668
depth[np.logical_not(mask)] = np.nan
77-
depth = (depth - min_val) / (max_val - min_val + 1e-10)
69+
vmin = depth[mask].min()
70+
vmax = depth[mask].max()
71+
depth = (depth - vmin) / (vmax - vmin)
7872

7973
img = Image.fromarray(
8074
np.rint(cmap(depth) * 255.0).astype(np.int8), mode="RGBA"
8175
).convert("RGB")
8276
return img
8377

84-
8578
def get_rgb_image(image, max=255.0):
8679
"""Convert an RGB image to a PIL image.
8780

0 commit comments

Comments
 (0)