[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 | autumn |
COLORMAP_BONE Python: cv.COLORMAP_BONE | bone |
COLORMAP_JET Python: cv.COLORMAP_JET | jet |
COLORMAP_WINTER Python: cv.COLORMAP_WINTER | winter |
COLORMAP_RAINBOW Python: cv.COLORMAP_RAINBOW | rainbow |
COLORMAP_OCEAN Python: cv.COLORMAP_OCEAN | ocean |
COLORMAP_SUMMER Python: cv.COLORMAP_SUMMER | summer |
COLORMAP_SPRING Python: cv.COLORMAP_SPRING | spring |
COLORMAP_COOL Python: cv.COLORMAP_COOL | cool |
COLORMAP_HSV Python: cv.COLORMAP_HSV | HSV |
COLORMAP_PINK Python: cv.COLORMAP_PINK | pink |
COLORMAP_HOT Python: cv.COLORMAP_HOT | hot |
COLORMAP_PARULA Python: cv.COLORMAP_PARULA | parula |
COLORMAP_MAGMA Python: cv.COLORMAP_MAGMA | magma |
COLORMAP_INFERNO Python: cv.COLORMAP_INFERNO | inferno |
COLORMAP_PLASMA Python: cv.COLORMAP_PLASMA | plasma |
COLORMAP_VIRIDIS Python: cv.COLORMAP_VIRIDIS | viridis |
COLORMAP_CIVIDIS Python: cv.COLORMAP_CIVIDIS | cividis |
COLORMAP_TWILIGHT Python: cv.COLORMAP_TWILIGHT | twilight |
COLORMAP_TWILIGHT_SHIFTED Python: cv.COLORMAP_TWILIGHT_SHIFTED | twilight 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 |