img_augmentation.py 文件源码

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

项目:lasagne_CNN_framework 作者: woshialex 项目源码 文件源码
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.
    """
    if random_state is None:
        random_state = np.random.RandomState(None)

    shape = image.shape[1:];
    dx = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * alpha
    dy = gaussian_filter((random_state.rand(*shape) * 2 - 1), sigma, mode="constant", cval=0) * 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))

    #return map_coordinates(image, indices, order=1).reshape(shape)
    res = np.zeros_like(image);
    for i in xrange(image.shape[0]):
        res[i] = map_coordinates(image[i], indices, order=1).reshape(shape)
    return res;
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号