在python中调整图像大小 [英] Resizing an image in python

查看:270
本文介绍了在python中调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张尺寸为(288,352)的图像.我想将其调整为(160,240). 我尝试了以下代码:

I have an image of size (288, 352). I want to resize it to (160, 240). I tried the following code:

im = imread('abc.png')
img = im.resize((160, 240), Image.ANTIALIAS)

但是它给出了错误TypeError: an integer is required 请告诉我最好的方法.

But it gives an error TypeError: an integer is required Please tell me the best way to do it.

推荐答案

matplotlib.pyplot.imread(或scipy.ndimage.imread)返回NumPy数组,而不是PIL图像.

matplotlib.pyplot.imread (or scipy.ndimage.imread) returns a NumPy array, not a PIL Image.

代替尝试:

In [25]: import Image
In [26]: img = Image.open(FILENAME)
In [32]: img.size
Out[32]: (250, 250)

In [27]: img = img.resize((160, 240), Image.ANTIALIAS)

In [28]: img.size
Out[28]: (160, 240)

这篇关于在python中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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