Skip to content Skip to sidebar Skip to footer

Convert Numpy Array To RGB Img With Custom Pallete

I want to convert a numpy.ndarray: out = [[12 12 12 ..., 12 12 12] [12 12 12 ..., 12 12 12] [12 12 12 ..., 12 12 12] ..., [11 11 11 ..., 10 10 10] [11 11 1

Solution 1:

You can just use the full image as index for the look-up table.

Something like data = colors_pal[out]

import numpy as np
import matplotlib.pyplot as plt
import skimage.data
import skimage.color

# sample image, grayscale 8 bits
img = skimage.color.rgb2gray(skimage.data.astronaut())
img = (img * 255).astype(np.uint8)
# sample LUT from matplotlib
lut = (plt.cm.jet(np.arange(256)) * 255).astype(np.uint8)

# apply LUT and display
plt.imshow(lut[img])
plt.show()

result


Post a Comment for "Convert Numpy Array To RGB Img With Custom Pallete"