英文:
Why cmap='Greys' does not do anything for a colored image?
问题
为什么仅仅改变颜色映射并不能将彩色图像转换为黑白图像?
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()
英文:
Why simply changing the color map does not convert a colored image to black and white?
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()
答案1
得分: 2
img
是一个类似数组的数据结构。它的大小为(M,N,3)
,其中M
和N
是原始图像的边长,以像素为单位。这意味着数据格式为RGB值。根据matplotlib文档,如果输入数组为RBG或RBGA格式,plt.imshow(...)
的cmap
参数将被忽略。
文档链接:https://matplotlib.org/stable/api/_as-gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow
英文:
Explanation
img
is an array-like data structure. It has size (M,N,3)
where M
and N
are the side lengths of the original image, in pixels. This means that the data is formatted as RGB values. According to the matplotlib documentation, the cmap
parameter of plt.imshow(...)
is ignored if the input array is in RBG or RBGA format.
Link to documentation: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html#matplotlib.pyplot.imshow
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论