久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 Python OpenCV 將灰度圖像轉(zhuǎn)換為熱圖圖像

How to convert a grayscale image to heatmap image with Python OpenCV(如何使用 Python OpenCV 將灰度圖像轉(zhuǎn)換為熱圖圖像)
本文介紹了如何使用 Python OpenCV 將灰度圖像轉(zhuǎn)換為熱圖圖像的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一個(gè) (540, 960, 1) 形狀的圖像,其值范圍為黑白的 [0..255].我需要將其轉(zhuǎn)換為熱圖"表示.例如,具有 255 的像素應(yīng)該是最熱的,而具有 0 的像素應(yīng)該是最不熱的.其他介于兩者之間.我還需要將熱圖作為 Numpy 數(shù)組返回,以便稍后將它們合并到視頻中.有沒(méi)有辦法做到這一點(diǎn)?

解決方案

這里有兩種方法,一種使用Matplotlib,一種只使用OpenCV

方法#1: OpenCV +

我們可以使用 OpenCV 內(nèi)置的熱圖功能.這是使用 cv2.COLORMAP_HOT 熱圖

的結(jié)果

代碼

導(dǎo)入 cv2圖像 = cv2.imread('frame.png', 0)熱圖 = cv2.applyColorMap(圖像,cv2.COLORMAP_HOT)cv2.imshow('熱圖', 熱圖)cv2.waitKey()


注意:雖然 OpenCV 的內(nèi)置實(shí)現(xiàn)簡(jiǎn)短快捷,但我建議使用方法 #1,因?yàn)橛懈蟮念伾珗D選擇.Matplotlib 有 數(shù)百種不同的顏色圖并允許您在 OpenCV 時(shí)創(chuàng)建自己的自定義顏色圖只有12個(gè)可供選擇.這是內(nèi)置的 OpenCV 顏色圖選擇:

I have a (540, 960, 1) shaped image with values ranging from [0..255] which is black and white. I need to convert it to a "heatmap" representation. As an example, pixels with 255 should be of most heat and pixels with 0 should be with least heat. Others in-between. I also need to return the heat maps as Numpy arrays so I can later merge them to a video. Is there a way to achieve this?

解決方案

Here are two methods, one using Matplotlib and one using only OpenCV

Method #1: OpenCV + matplotlib.pyplot.get_cmap

To implement a grayscale (1-channel) -> heatmap (3-channel) conversion, we first load in the image as grayscale. By default, OpenCV reads in an image as 3-channel, 8-bit BGR. We can directly load in an image as grayscale using cv2.imread() with the cv2.IMREAD_GRAYSCALE parameter or use cv2.cvtColor() to convert a BGR image to grayscale with the cv2.COLOR_BGR2GRAY parameter. Once we load in the image, we throw this grayscale image into Matplotlib to obtain our heatmap image. Matplotlib returns a RGB format so we must convert back to Numpy format and switch to BGR colorspace for use with OpenCV. Here's a example using a scientific infrared camera image as input with the inferno colormap. See choosing color maps in Matplotlib for available built-in colormaps depending on your desired use case.

Input image:

Output heatmap image:

Code

import matplotlib.pyplot as plt
import numpy as np
import cv2

image = cv2.imread('frame.png', 0)
colormap = plt.get_cmap('inferno')
heatmap = (colormap(image) * 2**16).astype(np.uint16)[:,:,:3]
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_RGB2BGR)

cv2.imshow('image', image)
cv2.imshow('heatmap', heatmap)
cv2.waitKey()

Method #2: cv2.applyColorMap()

We can use OpenCV's built in heatmap function. Here's the result using the cv2.COLORMAP_HOT heatmap

Code

import cv2

image = cv2.imread('frame.png', 0)
heatmap = cv2.applyColorMap(image, cv2.COLORMAP_HOT)

cv2.imshow('heatmap', heatmap)
cv2.waitKey()


Note: Although OpenCV's built-in implementation is short and quick, I recommend using Method #1 since there is a larger colormap selection. Matplotlib has hundreds of various colormaps and allows you to create your own custom color maps while OpenCV only has 12 to choose from. Here's the built in OpenCV colormap selection:

這篇關(guān)于如何使用 Python OpenCV 將灰度圖像轉(zhuǎn)換為熱圖圖像的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周?chē)L制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 超碰精品在线 | 亚洲欧美一区二区在线观看 | 草久久久| 97av视频| 欧美a级成人淫片免费看 | 亚洲国产精品久久久久婷婷老年 | 精品亚洲一区二区 | 亚洲97 | 精品欧美一区二区在线观看欧美熟 | av国产精品毛片一区二区小说 | 久久久久国产一级毛片 | 欧美精品成人一区二区三区四区 | julia中文字幕久久一区二区 | 国产精品久久久久永久免费观看 | 成人福利视频 | 国产aaaaav久久久一区二区 | 国产一区二区久久久 | 国产成人精品一区二区 | 一区影院| 成人做爰www免费看 午夜精品久久久久久久久久久久 | 国产日韩视频 | 九九综合 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 日韩欧美一区二区三区 | www.三级| 国产精品一区二区视频 | 国产精品一区二区在线观看 | 欧美国产日韩在线 | 国产精品成人国产乱一区 | 亚洲精品一区国语对白 | 国产日韩一区二区 | 国际精品鲁一鲁一区二区小说 | 中文字幕一二三区 | 国产一区二区三区久久久久久久久 | 粉嫩一区二区三区国产精品 | 亚洲视频免费在线观看 | 久久精品国产精品青草 | 国产精品自拍视频网站 | 久久综合一区 | 国产精品国产三级国产aⅴ无密码 | 日韩欧美网 |