python--scipy.misc.imresize()関数の例

904 ワード

この関数は名前のように、画像の形状を再調整するために使用されます.
抽象的に言えば、コードを直接見ます.
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/beili.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%
以上のプログラム出力:
(356, 600, 3)(200, 500, 3)(178, 300, 3)(17, 30, 3)
具体的な使い方はコードコメントを参照してください.