denoise_cnn_autoencoder.py 文件源码

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

项目:road-segmentation 作者: paramoecium 项目源码 文件源码
def load_patches_to_predict(directory_path, num_images, patch_size=conf.patch_size, phase='test'):
    """
    Loads prediction images and splits them up into patches.

    :param directory_path: The directory to load images from
    :param num_images: Number of images to load
    :param patch_size: The desired patch size. For prediction, the stride will be 1.
    :param phase: Whether the image to load are from the test or training dataset.
                  Must be 'test' or 'train_cnn_output'.
                  (This is important for the filename and resizing size.)

    :return: A tensor of patches with dimensions
        (num_images, vertical patch count, horizontal patch count, patch_size, patch_size)
    """
    patches = []
    if phase == 'test':
        base_filename = "raw_test_%d_pixels"
        resize_size = conf.test_image_resize
    elif phase == 'train_cnn_output':
        base_filename = "raw_satImage_%.3d_pixels"
        resize_size = conf.train_image_resize
    else:
        raise ValueError('Unsupported phase')

    for i in range(1, num_images+1):
        imageid = base_filename % i
        image_filename = directory_path + imageid + ".png"

        if os.path.isfile(image_filename):
            img = mpimg.imread(image_filename)
            # Resize images s.t. one patch is represented by a single pixel
            img = resize(img, (resize_size, resize_size))

            # For prediction we always extract patches with stride 1 and then average the predictions
            patches.append(skimg.extract_patches(img, (patch_size, patch_size), extraction_step=1))
    stacked_image_patches = np.stack(patches)
    return stacked_image_patches
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号