preprocessing.py 文件源码

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

项目:deepjets 作者: deepjets 项目源码 文件源码
def zoom_image(image, zoom, out_width=25):
    """Return rescaled and cropped image array with width out_width.
    """
    if zoom < 1:
        raise ValueError("Zoom scale factor must be at least 1.")

    width, height = image.shape
    #if width < out_width:
    #    raise ValueError(
    #        "image width before zooming ({0}) is less "
    #        "than requested output width ({1})".format(width, out_width))
    out_height = int(np.rint(float(out_width * height) / width))
    t_width = int(np.rint(out_width * zoom))
    t_height = int(np.rint(out_height * zoom))
    if t_width // 2 != out_width // 2:
        t_width += 1
    if t_height // 2 != out_height // 2:
        t_height += 1
    # zoom with cubic interpolation
    t_image = transform.resize(image, (t_width, t_height), order=3)
    # crop
    return t_image[(t_width - out_width) / 2:(t_width + out_width) / 2,
                   (t_height - out_height) / 2:(t_height + out_height) / 2]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号