Py学习  »  Python

在Python中调整图像大小

Turing • 5 年前 • 1813 次点击  

def process_image(image):

    size = 256, 256
    image.thumbnail(size, Image.ANTIALIAS)
    #image = image.crop((128 - 112, 128 - 112, 128 + 112, 128 + 112))
    npImage = np.array(image)
    npImage = npImage/255.

    return npImage

我希望所有的图片都是一样的大小。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53759
 
1813 次点击  
文章 [ 2 ]  |  最新文章 5 年前
Tom
Reply   •   1 楼
Tom    6 年前

image.resize((256, 256), Image.ANTIALIAS) 

第一个数字(256)是以像素为单位的宽度。

第二个数字(256)是以像素为单位的高度。

ANTIALIAS是一种高质量的下采样滤波器


def process_image(image):

    size = 256, 256
    image.thumbnail(size, Image.ANTIALIAS)
    #image = image.crop((128 - 112, 128 - 112, 128 + 112, 128 + 112))

    image.resize((256, 256), Image.ANTIALIAS) 
    #resizes the image and gives it width and height of 256 pixels  

    npImage = np.array(image)
    npImage = npImage/255.

    return npImage
Iain Shelvington
Reply   •   2 楼
Iain Shelvington    6 年前

缩略图功能保留纵横比。您应该使用resize函数

image.resize(size, Image.ANTIALIAS)