processing.py 文件源码

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

项目:Ultras-Sound-Nerve-Segmentation---Kaggle 作者: Simoncarbo 项目源码 文件源码
def elastic_transform(image, alpha, sigma, random_state=None):
    """Elastic deformation of images as described in [Simard2003]_.
    .. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for
       Convolutional Neural Networks applied to Visual Document Analysis", in
       Proc. of the International Conference on Document Analysis and
       Recognition, 2003.

       Code taken from https://gist.github.com/fmder/e28813c1e8721830ff9c
       slightly modified
    """
    min_im = np.min(image)
    max_im = np.max(image)

    if random_state is None:
        random_state = np.random.RandomState(None)

    shape = image.shape
    dx = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0)
    dx = dx/np.max(dx)* alpha
    dy = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0)
    dy = dy/np.max(dy)* alpha

    x, y = np.meshgrid(np.arange(shape[1]), np.arange(shape[0]))
    indices = np.reshape(y+dy, (-1, 1)), np.reshape(x+dx, (-1, 1))

    image_tfd = map_coordinates(image,indices,order=3).reshape(shape)
    image_tfd[image_tfd>max_im] = max_im
    image_tfd[image_tfd<min_im] = min_im

    return image_tfd
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号