Skip to content

Commit

Permalink
fix(rgb): ensure rgb values are in 0-1 range
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnec committed Sep 12, 2020
1 parent 4c0a74d commit 4b5f5a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion depthy/misc/plots.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import warnings
from depthy.misc import Normalizer

try:
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -42,9 +43,12 @@ def plot_point_cloud(disp_arr: np.ndarray,
zz = disp_arr[:, ::-1][::down_scale, ::down_scale, ...]
xx, yy = np.meshgrid(np.arange(zz.shape[1]), np.arange(zz.shape[0]))

# normalize rgb values to 0-1 range
rgb = Normalizer(rgb).type_norm(new_min=0, new_max=1)

# plot depth data
fig, ax = (plt.figure(), plt.axes(projection='3d')) if ax is None else (None, ax)
ax.scatter(xx, yy, zz, c=rgb.reshape(-1, rgb.shape[-1]) / rgb.max(), s=0.5)
ax.scatter(xx, yy, zz, c=rgb.reshape(-1, rgb.shape[-1]), s=0.5)
ax.view_init(view_angles[0], view_angles[1])

return ax
3 changes: 3 additions & 0 deletions tests/test_plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def test_point_cloud(self):
# test valid case
plot_point_cloud(disp_arr=np.ones([6, 6]), rgb_img=np.ones([6, 6, 3]), down_scale=2)

# test invalid rgb values
plot_point_cloud(disp_arr=np.ones([6, 6]), rgb_img=np.ones([6, 6, 3])*-1, down_scale=2)

# test Axes3D argument
fig, ax = plt.figure(), plt.axes(projection='3d')
ax_type = type(ax)
Expand Down

0 comments on commit 4b5f5a7

Please sign in to comment.