Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

opencv - how to superimpose heatmap on a base image?

Please look at this github page. I want to generate heat maps in this way using Python PIL,open cv or matplotlib library. Can somebody help me figure it out? Superimposed heatmaps

I could create a heat map for my network at the same size as the input, but I am not able superimpose them. The heatmap shape is (800,800) and the base image shape is (800,800,3)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can superimpose your heatmap on the image using the function cv2.addweighted() available in OpenCV.

Here is an example

Sample image:

img = cv2.imread('Sample.jpg', 1)
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

enter image description here

Heatmap:

heatmap_img = cv2.applyColorMap(gray_img, cv2.COLORMAP_JET)

enter image description here

Superimposed:

Now if you want to superimpose this on top of the original image, you can use cv2.addweighted() function

fin = cv2.addWeighted(heatmap_img, 0.7, img, 0.3, 0)

enter image description here

You can vary the weight parameters in the function for both the images.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...