patches_to_image#

deepinv.utils.patches_to_image(patches, stride, img_size=None, reduce_overlap='mean')[source]#

Reconstruct images from overlapping 2D patches.

Parameters:
  • patches (torch.Tensor) – Patches tensor of shape (B, C, n_rows, n_cols, patch_h, patch_w).

  • stride (int | tuple[int, int]) – Stride between adjacent patches as (stride_h, stride_w).

  • img_size (tuple[int, int]) – Optional target output image size (height, width). If provided, output is cropped to this size.

  • reduce_overlap (str) – How to reduce overlapping areas, "sum" or "mean" (default).

Returns:

Reconstructed images of shape (B, C, H, W).

Return type:

Tensor

Note

If reduce_overlap is set to "mean" and the patch size, stride and image size are compatible, this function is the exact inverse of deepinv.utils.image_to_patches(). If they are not compatible, an extra cropping is needed to get the exact inverse, which can be achieved by providing the img_size argument.