utils.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:deep-style-transfer 作者: albertlai 项目源码 文件源码
def load_image(path, image_h, image_w, zoom=False):
    # load image
    img = skimage.io.imread(path)
    if img.ndim < 3:
        img = skimage.color.gray2rgb(img)
    # we crop image from center
    ratio = float(image_h) / image_w
    height = int(img.shape[0])
    width = int(img.shape[1])
    yy = 0
    xx = 0
    if height > width * ratio: #too tall
        yy = int(height - width * ratio) // 2
        height = int(width * ratio)
    else: # too wide
        xx = int(width - height / ratio) // 2
        width = int(height / ratio)
    if zoom:
        yy += int(height / 6)
        xx += int(height / 6)
        height = int(height * 2/ 3)
        width = int(width * 2 / 3)
    crop_img = img[yy: yy + height, xx: xx + width]
    # resize 
    resized_img = skimage.transform.resize(crop_img, (image_h, image_w), preserve_range=True)
    centered_img = resized_img - MEAN_VALUES
    return centered_img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号