Last active
January 14, 2020 02:27
-
-
Save yuki-inaho/8f53e9dde1f2228c9e686f7f3e480afc to your computer and use it in GitHub Desktop.
Colorize Long Int 1Channel Images (such as IR, Depth...)
This file contains hidden or 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
| def colorize_long_int_img(img, max_var): | |
| img_colorized = np.zeros([img.shape[0],img.shape[1],3]).astype(np.uint8) | |
| img_colorized[:,:,1]=255 | |
| img_colorized[:,:,2]=255 | |
| img_hue = img.copy().astype(np.float32) | |
| img_hue[np.where(img_hue > max_var)] = 0 | |
| zero_idx = np.where((img_hue>max_var) | (img_hue == 0)) | |
| img_hue *= 255.0/max_var | |
| img_colorized[:,:,0] = img_hue.astype(np.uint8) | |
| img_colorized = cv2.cvtColor(img_colorized, cv2.COLOR_HSV2RGB) | |
| img_colorized[zero_idx[0], zero_idx[1],:] = 0 | |
| return img_colorized |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment