Search code examples
opencvimage-processingpython-imaging-libraryheatmap

Superimpose heatmap on a base image OpenCV Python


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)


Solution

  • Updated Answer -- 29th April, 2022.

    After the repeated comments I have decided to update this post with a better visualization.

    Consider the following image:

    img = cv2.imread('image_path')
    

    enter image description here

    I obtained a binary image after performing binary threshold on the a-channel of the LAB converted image:

    lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
    a_component = lab[:,:,1]
    th = cv2.threshold(a_component,140,255,cv2.THRESH_BINARY)[1]
    

    enter image description here

    Applying Gaussian blur:

    blur = cv2.GaussianBlur(th,(13,13), 11)
    

    enter image description here

    The resulting heatmap:

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

    enter image description here

    Finally, superimposing the heatmap over the original image:

    super_imposed_img = cv2.addWeighted(heatmap_img, 0.5, img, 0.5, 0)
    

    enter image description here

    Note: You can vary the weight parameters in the function cv2.addWeighted and observe the differences.