deepmr.patches2tensor

Contents

deepmr.patches2tensor#

deepmr.patches2tensor(patches, shape, patch_shape, patch_stride=None)[source]#

Accumulate patches into a tensor.

Adapted from [1] using [2].

Parameters:
  • patches (torch.Tensor) –

    Tensor of (overlapping) patches of shapes:

    • 1D: (..., npatches_z, patch_size_x)

    • 2D: (..., npatches_z, npatches_y, patch_size_y, patch_size_x)

    • 3D: (..., npatches_z, npatches_y, npatches_x, patch_size_z, patch_size_y, patch_size_x)

  • shape (Iterable[int]) – Output shape of length ndim. If scalar, assume isotropic matrix of shape ndim * [shape].

  • patch_shape (Iterable[int]) – Shape of the patch of length ndim.

  • patch_stride (Iterable[int], optional) – Stride of the windows of length ndim. The default it is the patch size (i.e., non overlapping).

Returns:

image – N-dimensional image tensor, with the last ndim dimensions being the image dimensions.

Return type:

torch.Tensor

References

[1] https://discuss.pytorch.org/t/how-to-split-tensors-with-overlap-and-then-reconstruct-the-original-tensor/70261

[2] f-dangel/unfoldNd