opencv: cv2.applyColorMap 伪色彩

用途

在图像处理中,伪色彩用途广泛。在OpenCV库中,常见的伪色彩模式都可通过 cv2.applyColorMap(src, userColor[, dst]) 直接调用,很是方便快捷。

例如伪色彩中的 COLORMAP_JET模式,就常被用于生成我们所常见的 热力图
这里写图片描述

Syntax

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

原图:

opencv: cv2.applyColorMap 伪色彩_第1张图片

伪色彩图:

COLORMAP_AUTUMN = 0:
opencv: cv2.applyColorMap 伪色彩_第2张图片

COLORMAP_BONE = 1:
opencv: cv2.applyColorMap 伪色彩_第3张图片

COLORMAP_JET = 2:
opencv: cv2.applyColorMap 伪色彩_第4张图片

COLORMAP_WINTER = 3:
opencv: cv2.applyColorMap 伪色彩_第5张图片

COLORMAP_RAINBOW = 4:
opencv: cv2.applyColorMap 伪色彩_第6张图片

COLORMAP_OCEAN = 5:
opencv: cv2.applyColorMap 伪色彩_第7张图片

COLORMAP_SUMMER = 6:
opencv: cv2.applyColorMap 伪色彩_第8张图片

COLORMAP_SPRING = 7:
opencv: cv2.applyColorMap 伪色彩_第9张图片

COLORMAP_COOL = 8:
opencv: cv2.applyColorMap 伪色彩_第10张图片

COLORMAP_HSV = 9:
opencv: cv2.applyColorMap 伪色彩_第11张图片

COLORMAP_PINK = 10:
opencv: cv2.applyColorMap 伪色彩_第12张图片

COLORMAP_HOT = 11:
opencv: cv2.applyColorMap 伪色彩_第13张图片

12:
opencv: cv2.applyColorMap 伪色彩_第14张图片

Code

附上自己写的实验代码:

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)

你可能感兴趣的:(OpenCV,OpenCV-Python)