-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2633 from wkentaro/pure_python_utils_color
Replace color.pyx with color.py for better compatibility
- Loading branch information
Showing
3 changed files
with
36 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
jsk_recognition_utils/python/jsk_recognition_utils/color.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
jsk_recognition_utils/python/jsk_recognition_utils/color.pyx
This file was deleted.
Oops, something went wrong.