枕头Image对象和数组numpy的转换之间的尺寸变化 [英] Conversion between Pillow Image object and numpy array changes dimension

查看:453
本文介绍了枕头Image对象和数组numpy的转换之间的尺寸变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的枕头和numpy的,但与枕头Image对象和数组numpy的之间的转换问题。

I am using Pillow and numpy, but have a problem with conversion between Pillow Image object and numpy array.

当我执行以下code,其结果是怪异的。

when I execute following code, the result is weird.

im = Image.open(os.path.join(self.img_path, ifname))
print im.size
in_data = np.asarray(im, dtype=np.uint8)
print in_data.shape

结果是

(1024, 768)
(768, 1024)

为什么尺寸改变了吗?

Why dimension is changed?

推荐答案

在numpy的IM可能列为主,而数组是行优先

im maybe column-major while arrays in numpy are row-major

DO IN_DATA = in_data.T 来转蟒蛇阵列

也许应该检查IN_DATA与 matplotlib imshow ,以确保图片看起来正确的。

probably should check in_data with matplotlib's imshow to make sure the picture looks right.

但是,你知道,matplotlib自带的,让你直接numpy的阵列自身的加载功能?请参阅: http://matplotlib.org/users/image_tutorial.html

But do you know that matplotlib comes with its own loading functions that gives you numpy arrays directly? See: http://matplotlib.org/users/image_tutorial.html

这篇关于枕头Image对象和数组numpy的转换之间的尺寸变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆