python中ndarray怎么保存_将python中的numpy.ndarray保存为图像

b=ndimage.gaussian_filter(imagefile,5)

是python的新手,无法解决这个问题.

如何将b保存为图像,b的类型为’numpy.ndarray’?

试过这些,

1.

im = Image.fromarray(b)

im.save("newfile.jpeg")

错误:TypeError(“无法处理此数据类型”)

2.

imsave('newfile.jpg', b)

错误:ValueError:’arr’没有适合任何模式的数组形状.

将ndarray保存到图像中的正确方法是什么?

编辑:

解决了:

im = Image.fromarray(b)

im.save(‘newfile.jpeg’)工作,我加载图像的方式是错误的,

file = Image.open("abc.jpg")

imagefile = file.load()

//我在加载后使用的是imagefile,它没有给出正确的形状来重建图像.

//相反如果我使用文件(即打开后直接,我可以通过上面的方法保存)

解决方法:

我认为最好的方法是使用matplotlib imshow.

使用图像库:

import Image

import numpy as np

x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)

im = Image.fromarray(x)

im.save('test.png')

Matplotlib版本:

import numpy as np

import matplotlib.pyplot as plt

x = np.array([[1, 2, 3], [4, 5, 6]], np.int32)

plt.imshow(x)

plt.savefig("array")

希望这可以帮助!

标签:python

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值