matplotlib 为什么cmap='Greys'对彩色图像没有任何作用?[duplicate]

q35jwt9p  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(191)
    • 此问题在此处已有答案**:

Matplotlib : What is the function of cmap in imshow?(1个答案)
4天前关闭。
为什么仅仅改变颜色Map表不能将彩色图像转换为黑白图像?

img = imread('https://cdn.shopify.com/s/files/1/1257/7487/articles/bee-flower_1024x.jpg?v=1585344606')
plt.imshow(img, cmap='Greys')

plt.colorbar()
plt.xticks([])
plt.yticks([])
plt.show()
klh5stk1

klh5stk11#

解释

img是一个类似数组的数据结构。它的大小为(M,N,3),其中MN是原始图像的边长(以像素为单位)。这意味着数据的格式为RGB值。根据matplotlib文档,如果输入数组为RBG或RBGA格式,则忽略plt.imshow(...)cmap参数。
文档链接:www.example.comhttps://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow

相关问题