[英]matplotlib: How to get imshow colors?
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. image是一个只有5个不同值的NxM numpy数组。 How can I get a list of the RGB values that these 5 values have been mapped to in the image shown with imshow? 如何获得在imshow显示的图像中这5个值已映射到的RGB值的列表?
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
如果您事先不知道图像中的值是什么,可以使用np.unique
查找所有唯一值,然后使用AxesImage
返回的imshow
norm
和cmap
属性
For example: 例如:
import numpy as np
import matplotlib.pyplot as plt
im = plt.imshow(image)
colours = im.cmap(im.norm(np.unique(image))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.