@@ -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' ))
4949cmap .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-
8578def get_rgb_image (image , max = 255.0 ):
8679 """Convert an RGB image to a PIL image.
8780
0 commit comments