Skip to content

Instantly share code, notes, and snippets.

@steermomo
Created June 27, 2019 05:13
Show Gist options
  • Save steermomo/5b457f96e8eb679e18dbf090855c4b4e to your computer and use it in GitHub Desktop.
Save steermomo/5b457f96e8eb679e18dbf090855c4b4e to your computer and use it in GitHub Desktop.
Python; Pseudo Color;将灰度图转为伪彩图;单色
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