python--scipy.misc.imresize()函数

这个函数如它名字一般,就是拿来重新调整图片的形状的~

import scipy.misc
import  numpy as np
 
def imread(path):
    img = scipy.misc.imread(path).astype(np.float)
    if len(img.shape) == 2:
        # grayscale
        img = np.dstack((img,img,img))
    elif img.shape[2] == 4:
        # PNG with alpha channel
        img = img[:,:,:3]
    return img
 
content_image = imread('examples/1.jpg')  # 读取content图片
print(content_image.shape)  #原图shape
 
content_image1 = scipy.misc.imresize(content_image, (200,500))
print(content_image1.shape)  #输入固定大小调整shape
 
content_image2 = scipy.misc.imresize(content_image, 0.5)
print(content_image2.shape)   #输入比例调整shape
 
content_image3 = scipy.misc.imresize(content_image, 5)
print(content_image3.shape)   #输入一个大于1的数,默认为百分比。例如输入5就等于5%

 

 

你可能感兴趣的:(Python,Tensorflow)