denoise_cnn_autoencoder.py 文件源码

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

项目:road-segmentation 作者: paramoecium 项目源码 文件源码
def reconstruct_image_from_patches(img_data, patches_per_predict_image_dim, size):
    """
    Reconstruct single image from multiple image patches.
    IMPORTANT: overlapping patches are averaged

    Args:
        img_data: An array with dimensions (patches_per_predict_image_dim**2, patch size, patch size)
        patches_per_predict_image_dim: Number of patches for one dimension. We assume image have the same
                                       dimension horizontally as well as vertically.
        size: Height/Widgth of the target image.
    Returns:
        recontructed image: An image of (size x size) reconstructed from the patches
    """

    reconstruction = np.zeros((size,size))
    n = np.zeros((size,size))
    idx = 0

    # Loop through all the patches in 2-dim and sum up the pixel values.
    # (We split up the image with stride 1 before)
    # Also keep a count array
    for i in range(patches_per_predict_image_dim):
        for j in range(patches_per_predict_image_dim):
            reconstruction[i:(i+conf.patch_size),j:(j+conf.patch_size)] += img_data[idx,:,:,0]
            n[i:(i+conf.patch_size),j:(j+conf.patch_size)] += 1
            idx += 1

    #Return the arithmetic average
    return np.divide(reconstruction, n)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号