我导入了matplotlib.pyplot和NumPy
我想显示一个从桌面到绘图的图像,但是我得到了一个TypeError
。
代码:
img = (image) ( here do we need to give the location of the file or the file directly)
imshow(img, extent=[-25,25,-25,25], cmap = cm.bone)
colorbar()
Error: TypeError: Image data can not convert to float
我正在使用Pycharm作为我的ide。
你有点模棱两可
不,你不需要。你需要使用图像库来读取图像。
img="C:\image.jpg"
不读取图像!例如,要读取“png”图像,可以:
在matplotlib的文档Image tutorial上阅读更多内容
img
anumpy数组的类型是否正确?如果您使用枕头等读取图像,并且有一个图像对象,则必须从中获取numpy数组(
img.getdata()
)要么将img规范化,使其介于0.0和1.0之间,要么将其转换为uint8(
img=np.array(img, dtype=np.uint8)
)。相关问题 更多 >
编程相关推荐