- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如下图第一张所示,有一个bmp图像,其信息如下图第二张所示。但是在 IPython-notebook 上使用 matplotlib 的 plt.imshow() 函数显示时,颜色错误,如下图第三张。那我能知道原因吗?
谢谢!
原始文件已在 Dropbox https://dl.dropboxusercontent.com/u/26518813/test2.bmp 共享
在 IPython-notebook 上显示图像的代码是:
%pylab inline --no-import-all
from PIL import Image
plt.imshow(Image.open("./test/test2.bmp"))
最佳答案
发生这种情况是因为您实际上是使用 matplotlib.pyplot 将图像绘制为矩阵。 Matplotlib 不支持 .bmp
native 所以我认为默认cmap存在一些错误。在您的特定情况下,您有一个灰度图像。所以实际上你可以用 cmap="gray"
将颜色图更改为灰度图。 .
from PIL import Image
img= Image.open(r'./test/test2.bmp')
plt.imshow(img,cmap='gray',vmin=0,vmax=255)
img=matplotlib.image.imread(r'/Users/giacomo/Downloads/test2.bmp')
plt.imshow(img,cmap='gray',vmin=0,vmax=255)
.png
前。
PIL.Image
显示图像你可以使用这个:
from PIL import Image
img= Image.open( r'./test/test2.bmp')
img.show()
'P'
(调色板编码:每个像素一个字节,带有类 ImagePalette 的调色板将像素转换为颜色)。与
.convert
然后用 matplotlib
plt.imshow
绘制图像:
convertedimg=img.convert('P')
plt.imshow(convertedimg)
关于matplotlib - 为什么 bmp 图像在 IPython-notebook 上使用 matplotlib 的 plt.imshow 显示为错误颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641822/
.plt :在 RE 能段中,蹦床功能在 plt[n]除了 0,在 plt[0] 处有 .got.plt 解析器链接 .got .got.plt : 在 RW 段中,只是地址 我从这篇文章中学到的:
这是我的代码,我从 plt.savefig 和 plt.show 得到不同的结果 我尝试过使用bbox_inches='tight',但这使得图片尺寸变得不完全是700*400。 x=np.linsp
我一直在通过反汇编一些 C 代码来学习汇编语言。当我用 GDB 反汇编这个基本的 C 代码时: #include void main(void) { printf("Hello World\
在matplotlib.pyplot中,plt.clf()和plt.close()有什么区别?它们会以同样的方式运作吗? 我正在运行一个循环,在每次迭代结束时,我都会生成一个图形并保存该图。在第一次尝
我很好奇:PLT-Scheme(现在称为 Racket )中的“PLT”代表什么?我能得到的最接近答案是 this page 上的““PLT”指的是 Racket 开发团队的核心团队”。 . 最佳答案
我在使用 matplotlib 绘图时需要使用所需的 OTF 字体,但不知道如何访问它。我看到了How to use a (random) *.otf or *.ttf font in matplot
我正在尝试从 2D 矩阵中找出尽可能多的数据可视化工具(加分点是查看 2D 矩阵的任何其他好方法)。 我生成了很多热图,有人告诉我 pcolor 是要走的路(我现在使用 seaborn)。 为什么 p
我想知道matplotlib.pyplot的plt.plot(x,y)和plt.show()命令之间进行的基本 Backbone 流程。 详细说明一下,这段代码: plt.plot(x , y)
鉴于以下情况: import matplotlib.pyplot as plt import numpy as np #http://matplotlib.org/api/pyplot_api.htm
我正在尝试将普通的 matplotlib.pyplot plt.plot(x,y) 与变量 y 组合为变量 x 带有箱线图。但是,我只想在 x 的某些(可变)位置上绘制箱线图,但这在 matplotl
我想知道为什么有些人在 plt.show() 之前将 plt.draw() 放入他们的代码中。对于我的代码, plt.draw() 的行为似乎并没有改变输出的任何内容。我在互联网上进行了搜索,但找不到
我在这个 helpful answer 中发现了当在 y 轴上使用对数刻度时,plt.scatter() 和 plt.plot() 的行为不同。 使用 plot,我可以在使用 plt.show() 之
我正在尝试生成一个简单的 pyplot 条形图,Python 3.6.0。代码如下: import random import matplotlib.pyplot as plt import coll
from matplotlib import pyplot as plt import matplotlib.pyplot as plt 以上说法是否等价?哪种形式更具可读性/更好? 最佳答案 尽管它
这些meshgrid对我来说使用起来有点困惑。我正在尝试使用 x 和 y 坐标绘制散点图,并在散点图上叠加等高线图,并为 z 连续展开> 坐标。类似于高程图。 如果我将 meshgrid 与 x、y
这是我的代码中出现错误的部分(都与图表相关,但要点: plt.figure (figsize = (10,6)) plt.title ("Alfa x CL") plt.plot (Alpha,CL,
尝试构建已签名的 APK 时,失败并重复约 100 行: Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/pre
我想看看函数运行需要多长时间。在 PLT-Scheme 中最简单的方法是什么?理想情况下,我希望能够做这样的事情: > (define (loopy times) (if (zero? times
读完两本 Schemer 书后,我即将开始 HtDP,但也发现了 http://docs.plt-scheme.org/guide Material 。 前面提到的书似乎更针对 Scheme,而后者更
我的数据集如下所示: Month DeviceType AvgRevenue 0 201608 desktop 3.029642 1 201608 mobile
我是一名优秀的程序员,十分优秀!