Skip to content

Commit

Permalink
Merge pull request #2633 from wkentaro/pure_python_utils_color
Browse files Browse the repository at this point in the history
Replace color.pyx with color.py for better compatibility
  • Loading branch information
k-okada committed Oct 8, 2021
2 parents f32cf54 + 9ee9bfb commit 15d5681
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ endif()
include_directories(${Numpy_INCLUDE_DIRS})
cython_add_module(nms nms.pyx)
set_target_properties(nms PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
cython_add_module(color color.pyx)
set_target_properties(color PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
install(TARGETS nms color
install(TARGETS nms
ARCHIVE DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
)
35 changes: 35 additions & 0 deletions jsk_recognition_utils/python/jsk_recognition_utils/color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np


# Taken from https://github.com/wkentaro/imgviz/blob/master/imgviz/label.py # NOQA
def labelcolormap(N=256):
"""Label colormap.
Parameters
----------
N: int
Number of labels (default: 256).
Returns
-------
cmap: numpy.ndarray, (N, 3), numpy.uint8
Label id to colormap.
"""

def bitget(byteval, idx):
shape = byteval.shape + (8,)
return np.unpackbits(byteval).reshape(shape)[..., -1 - idx]

i = np.arange(N, dtype=np.uint8)
r = np.full_like(i, 0)
g = np.full_like(i, 0)
b = np.full_like(i, 0)

i = np.repeat(i[:, None], 8, axis=1)
i = np.right_shift(i, np.arange(0, 24, 3)).astype(np.uint8)
j = np.arange(8)[::-1]
r = np.bitwise_or.reduce(np.left_shift(bitget(i, 0), j), axis=1)
g = np.bitwise_or.reduce(np.left_shift(bitget(i, 1), j), axis=1)
b = np.bitwise_or.reduce(np.left_shift(bitget(i, 2), j), axis=1)

cmap = np.stack((r, g, b), axis=1).astype(np.uint8)
return cmap
31 changes: 0 additions & 31 deletions jsk_recognition_utils/python/jsk_recognition_utils/color.pyx

This file was deleted.

0 comments on commit 15d5681

Please sign in to comment.