How to add a fake thermal effect to images I am working on a project to convert a normal RGB image to thermal images. I applied color maps using Matplotlib library and got an array which then I converted back to the RGBA image using Image.fromarray() available in the PIL library.
Expected Output:

Actual Output

My code is given below:
from PIL import Image, ImageOps
import matplotlib as mpl
import matplotlib.cm as mtplitcm
import PIL
import numpy as np
from matplotlib import cm

input_image = Image.open(&quot;/Users/adwaitnaik/Desktop/github/blendpy/test_data_for_yolo/lion.png&quot;)
gray = ImageOps.grayscale(input_image)

gray.show()

#initialize the colormap 
colormap = mpl.cm.jet

#normalize
cNorm = mpl.colors.Normalize(vmin=0, vmax=255)

#initialize the mapping
scalarMap = mtplitcm.ScalarMappable(norm=cNorm, cmap=colormap)

#create image array
image_array = scalarMap.to_rgba(gray)

#convert to numpy array
image_np = np.asarray(image_array)

image_np


#image_array
image_colored = Image.fromarray(image_np,'RGB')

image_colored.show()

This is the image I used as Input

Can anyone suggest a workaround?
Thanks
After experimenting with a couple of libraries, my code finally worked with OpenCV. Code and Output can be seen below.
Code
#this code uses color maps which works as thermal camera filter on the input image

import sys
import numpy as np
import cv2
import matplotlib as mpl
import matplotlib.cm as mtpltcm


def main(argv):

    while (True):
        # read the file
        input_img = cv2.imread('path_to_the_file')

        # convert image into grayscale
        gray = cv2.cvtColor(input_img, cv2.COLOR_BGR2GRAY)
        
        #initialize the colormap 
        colormap = mpl.cm.jet

        #add a normalization
        cNorm = mpl.colors.Normalize(vmin=0, vmax=255)

        #init the mapping
        scalarMap = mtpltcm.ScalarMappable(norm=cNorm, cmap=colormap)
    
        
        colors = scalarMap.to_rgba(gray)
        
        #to display the image
        cv2.imshow(&quot;_animal_name&quot;,colors)
            
        if cv2.waitKey(1) &amp; 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()

if __name__ == '__main__':
    sys.exit(main(sys.argv))

Expected Output