image_utils.py 文件源码

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

项目:lung-cancer-detector 作者: YichenGong 项目源码 文件源码
def elastic_transform_2d(img, alpha, sigma, random_mode=True, probability=0.5):
    #Taken from: https://gist.github.com/chsasank/4d8f68caf01f041a6453e67fb30f8f5a
    if random_mode:
        if random.random() < probability:
            return img

    dx = nd.gaussian_filter((random_state.rand(img.shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
    dy = nd.gaussian_filter((random_state.rand(img.shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha

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

    return apply_elastic(img, indices), indices
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号