image_tfs.py 文件源码

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

项目:tanda 作者: HazyResearch 项目源码 文件源码
def TF_elastic_deform(img, alpha=1.0, sigma=1.0):
    """Elastic deformation of images as described in Simard 2003"""
    assert len(img.shape) == 3
    h, w, nc = img.shape
    if nc != 1:
        raise NotImplementedError("Multi-channel not implemented.")

    # Generate uniformly random displacement vectors, then convolve with gaussian kernel
    # and finally multiply by a magnitude coefficient alpha
    dx = alpha * gaussian_filter(
        (np.random.random((h, w)) * 2 - 1), sigma, mode="constant", cval=0
    )
    dy = alpha * gaussian_filter(
        (np.random.random((h, w)) * 2 - 1), sigma, mode="constant", cval=0
    )

    # Map image to the deformation mesh
    x, y    = np.meshgrid(np.arange(h), np.arange(w), indexing='ij')
    indices = np.reshape(x+dx, (-1, 1)), np.reshape(y+dy, (-1, 1))

    return map_coordinates(img.reshape((h,w)), indices, order=1).reshape(h,w,nc)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号