fast_neural_style.py 文件源码

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

项目:neural_style 作者: wangchen1ren 项目源码 文件源码
def crop_image(image, shape):
    factor = float(min(shape[:2])) / min(image.shape[:2])
    new_size = [int(image.shape[0] * factor), int(image.shape[1] * factor)]
    if new_size[0] < shape[0]:
        new_size[0] = shape[0]
    if new_size[1] < shape[0]:
        new_size[1] = shape[0]
    resized_image = transform.resize(image, new_size)
    sample = np.asarray(resized_image) * 256
    if shape[0] < sample.shape[0] or shape[1] < sample.shape[1]:
        xx = int((sample.shape[0] - shape[0]))
        yy = int((sample.shape[1] - shape[1]))
        x_start = xx / 2
        y_start = yy / 2
        x_end = x_start + shape[0]
        y_end = y_start + shape[1]
        sample = sample[x_start:x_end, y_start:y_end, :]
    return sample
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号