0

I have an assignment where I need to apply a colormap to an image and generate a numpy array. I am unsure how to create and apply the function to the image.

Here is what I have,

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap

mars_gray = mpimg.imread('img.png')
lum_img = mars_gray[:, :, 0]
plt.imshow(lum_img, cmap='gray')
print (lum_img)


def colorMapPlasma(red, green, blue):
    cdict = {'red':   [(0.0,  0.0, 0.0),
                       (0.2,  0.0, 0.14),
                       (0.75, 1.0, 1.0),
                       (1.0,  0.7, 0.7)],

             'green': [(0.0,  0.0, 0.14),
                       (0.24, 0.14, 0.24),
                       (0.3,  0.7, 0.7),
                       (0.4,  0.3, 0.0),
                      (1.0,  0.0, 0.0)],

             'blue':  [(0.0,  1.0, 1.0),
                       (0.28,  0.0, 0.0),
                       (1.0,  0.0, 0.0)]}
    return cdict

result = colorMapPlasma(lum_img[1],lum_img[2],lum_img[3])
print(result)

More Details in Screenshot

  • Is that the standard plasma colormap or is it a custom colormap? – jared Jun 16 '23 at 04:25
  • Does this answer your question? [Create own colormap using matplotlib and plot color scale](https://stackoverflow.com/questions/16834861/create-own-colormap-using-matplotlib-and-plot-color-scale) – jared Jun 16 '23 at 04:28
  • @jared, it is a custom colormap with the RGB representing the transfer functions – PythonNewbie Jun 16 '23 at 04:50

0 Answers0