9.opencv中伪彩色applyColorMap函数的应用

 在图像处理中,伪色彩用途广泛。例如伪色彩中的 COLORMAP_JET模式,就常被用于生成我们所常见的热力图。

# 对应函数语法
cv2.applyColorMap(src, userColor[, dst])
  •  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

具体的代码实现如下: 

import cv2
import matplotlib.pyplot as plt

img_gray = cv2.imread("girl.PNG", cv2.IMREAD_GRAYSCALE)

img1 = cv2.applyColorMap(img_gray, cv2.COLORMAP_AUTUMN)
img2 = cv2.applyColorMap(img_gray, cv2.COLORMAP_BONE)
img3 = cv2.applyColorMap(img_gray, cv2.COLORMAP_JET)
img4 = cv2.applyColorMap(img_gray, cv2.COLORMAP_WINTER)
img5 = cv2.applyColorMap(img_gray, cv2.COLORMAP_RAINBOW)
img6 = cv2.applyColorMap(img_gray, cv2.COLORMAP_OCEAN)
img7 = cv2.applyColorMap(img_gray, cv2.COLORMAP_SUMMER)
img8 = cv2.applyColorMap(img_gray, cv2.COLORMAP_SPRING)
img9 = cv2.applyColorMap(img_gray, cv2.COLORMAP_COOL)
img10 = cv2.applyColorMap(img_gray, cv2.COLORMAP_HSV)
img11 = cv2.applyColorMap(img_gray, cv2.COLORMAP_PINK)
img12 = cv2.applyColorMap(img_gray, cv2.COLORMAP_HOT)

title = ["COLORMAP_AUTUMN", "COLORMAP_BONE", "COLORMAP_JET", "COLORMAP_WINTER", "COLORMAP_RAINBOW",
         "COLORMAP_OCEAN", "COLORMAP_SUMMER", "COLORMAP_SPRING", "COLORMAP_COOL ", "COLORMAP_HSV",
         "COLORMAP_PINK", "COLORMAP_HOT"]
img_list = [img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12]

for i in range(len(title)):
    plt.subplot(3, 4, i + 1)  # 3x4的图第i个位置
    plt.imshow(img_list[i][:, :, ::-1])  # BGR->RGB
    plt.title(title[i], fontsize=8)
    plt.xticks([]), plt.yticks([])  # 隐藏刻度

plt.show()

原图: 9.opencv中伪彩色applyColorMap函数的应用_第1张图片

 输出结果图:

9.opencv中伪彩色applyColorMap函数的应用_第2张图片

 参考:https://blog.csdn.net/u013381011/article/details/78341861

https://blog.csdn.net/weixin_36670529/article/details/104001820

你可能感兴趣的:(opencv,opencv)