[opencv] applyColorMap

applyColorMap

功能

转化为热力图,因为热力图我们看的变化更加细微,在很多地方都用到了热力图。

最近在看CAM,所以记一记这个函数。

感觉还是很有用的。

代码

>>> import cv2 as cv
>>> import numpy as np
>>> img = cv.imread("./res.jpg")
>>> color_zero = np.zeros(shape = img.shape).astype(np.uint8)
>>> color_zero[0:50,0:50,:] = 254
>>> color_img = color_zero
>>> color_gray = cv.cvtColor(color_img,cv.COLOR_BGR2GRAY)
>>> color_app = cv.applyColorMap(color_gray,2)
>>> out = cv.addWeighted(img,0.5,color_app,0.5,0)
>>> cv.imwrite("out.jpg",out)
True


一般需要img为灰度图,然后根据灰度图亮度的大小转化为热力图。

函数参数

Enumerator
COLORMAP_AUTUMN Python: cv.COLORMAP_AUTUMN colorscale_autumn.jpgautumn
COLORMAP_BONE Python: cv.COLORMAP_BONE colorscale_bone.jpgbone
COLORMAP_JET Python: cv.COLORMAP_JET colorscale_jet.jpgjet
COLORMAP_WINTER Python: cv.COLORMAP_WINTER colorscale_winter.jpgwinter
COLORMAP_RAINBOW Python: cv.COLORMAP_RAINBOW colorscale_rainbow.jpgrainbow
COLORMAP_OCEAN Python: cv.COLORMAP_OCEAN colorscale_ocean.jpgocean
COLORMAP_SUMMER Python: cv.COLORMAP_SUMMER colorscale_summer.jpgsummer
COLORMAP_SPRING Python: cv.COLORMAP_SPRING colorscale_spring.jpgspring
COLORMAP_COOL Python: cv.COLORMAP_COOL colorscale_cool.jpgcool
COLORMAP_HSV Python: cv.COLORMAP_HSV colorscale_hsv.jpgHSV
COLORMAP_PINK Python: cv.COLORMAP_PINK colorscale_pink.jpgpink
COLORMAP_HOT Python: cv.COLORMAP_HOT colorscale_hot.jpghot
COLORMAP_PARULA Python: cv.COLORMAP_PARULA colorscale_parula.jpgparula
COLORMAP_MAGMA Python: cv.COLORMAP_MAGMA colorscale_magma.jpgmagma
COLORMAP_INFERNO Python: cv.COLORMAP_INFERNO colorscale_inferno.jpginferno
COLORMAP_PLASMA Python: cv.COLORMAP_PLASMA colorscale_plasma.jpgplasma
COLORMAP_VIRIDIS Python: cv.COLORMAP_VIRIDIS colorscale_viridis.jpgviridis
COLORMAP_CIVIDIS Python: cv.COLORMAP_CIVIDIS colorscale_cividis.jpgcividis
COLORMAP_TWILIGHT Python: cv.COLORMAP_TWILIGHT colorscale_twilight.jpgtwilight
COLORMAP_TWILIGHT_SHIFTED Python: cv.COLORMAP_TWILIGHT_SHIFTED colorscale_twilight_shifted.jpgtwilight shifted

官网API

Python:
dst = cv.applyColorMap( src, colormap[, dst] )
dst = cv.applyColorMap( src, userColor[, dst] )

Parameters

src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
dst The result is the colormapped source image. Note: Mat::create is called on dst.
userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256
Python:
dst = cv.applyColorMap( src, colormap[, dst] )
dst = cv.applyColorMap( src, userColor[, dst] )

Parameters

src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3.
dst The result is the colormapped source image. Note: Mat::create is called on dst.
colormap The colormap to apply, see ColormapTypes
posted @ 2019-06-22 14:17  aoru45  阅读(1736)  评论(0编辑  收藏  举报