cv2.applyColorMap 伪色彩

2022-09-03 19:16:23 浏览数 (1)

用途

在图像处理中,伪色彩用途广泛。在OpenCV库中,常见的伪色彩模式都可通过 cv2.applyColorMap(src, userColor[, dst]) 直接调用,很是方便快捷。例如伪色彩中的 COLORMAP_JET模式,就常被用于生成我们所常见的 热力图:

Syntax

代码语言:javascript复制
cv2.applyColorMap(src, userColor[, dst])

Args:

  • COLORMAP_AUTUMN = 0
  • COLORMAP_BONE = 1
  • COLORMAP_JET = 2
  • COLORMAP_WINTER = 3
  • COLORMAP_RAINBOW = 4
  • COLORMAP_OCEAN = 5
  • COLORMAP_SUMMER = 6
  • COLORMAP_SPRING = 7
  • COLORMAP_COOL = 8
  • COLORMAP_HSV = 9
  • COLORMAP_PINK = 10
  • COLORMAP_HOT = 11

Demo 原图:

伪色彩图:

COLORMAP_AUTUMN = 0:

COLORMAP_BONE = 1:

COLORMAP_JET = 2:

COLORMAP_WINTER = 3:

COLORMAP_RAINBOW = 4:

COLORMAP_OCEAN = 5:

COLORMAP_SUMMER = 6:

COLORMAP_SPRING = 7:

COLORMAP_COOL = 8:

COLORMAP_HSV = 9:

COLORMAP_PINK = 10:

COLORMAP_HOT = 11:

12:

Code

附上自己写的实验代码:

代码语言:javascript复制
import cv2

# COLORMAP_AUTUMN = 0,
# COLORMAP_BONE = 1,
# COLORMAP_JET = 2,
# COLORMAP_WINTER = 3,
# COLORMAP_RAINBOW = 4,
# COLORMAP_OCEAN = 5,
# COLORMAP_SUMMER = 6,
# COLORMAP_SPRING = 7,
# COLORMAP_COOL = 8,
# COLORMAP_HSV = 9,
# COLORMAP_PINK = 10,
# COLORMAP_HOT = 11

img = cv2.imread("girl.jpg")
for i in range(0, 13):
    im_color = cv2.applyColorMap(img, i)
    cv2.imwrite("{}.jpg".format(i), im_color)

0 人点赞