Created
June 27, 2019 05:13
-
-
Save steermomo/5b457f96e8eb679e18dbf090855c4b4e to your computer and use it in GitHub Desktop.
Python; Pseudo Color;将灰度图转为伪彩图;单色
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
from skimage import color | |
import numpy as np | |
def pseudo_color(arr: np.ndarray, hue: int): | |
"""生成伪彩图 | |
:param arr: 灰度图像 | |
:type arr: np.ndarray | |
:param hue: hsv空间的hue值, 用于指定颜色, 0~360 | |
:type hue: int | |
:return: [description] | |
:rtype: [type] | |
""" | |
v = (arr - arr.min()) / (arr.max()-arr.min()) # 通过v值控制亮度 | |
hue /= 360 | |
hsv = np.stack([np.ones(arr.shape) * hue, np.ones(arr.shape), v], axis=-1) | |
return color.hsv2rgb(hsv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment