Reputation: 2764
I've plotted an image using
import matplotlib.pyplot as plt
plt.imshow(image)
image is a NxM numpy array with only 5 different values. How can I get a list of the RGB values that these 5 values have been mapped to in the image shown with imshow?
Upvotes: 0
Views: 3779
Reputation: 69213
if you don't know in advance what your values in your image are going to be, you can use np.unique
to find all unique values, then use norm
and cmap
properties of the AxesImage
returned by imshow
For example:
import numpy as np
import matplotlib.pyplot as plt
im = plt.imshow(image)
colours = im.cmap(im.norm(np.unique(image))
Upvotes: 4