deepmr.tensor2patches#
- deepmr.tensor2patches(image, patch_shape, patch_stride=None)[source]#
View tensor as overlapping hyperectangular patches, with a given stride.
Adapted from [1, 2].
- Parameters:
image (torch.Tensor) – N-dimensional image tensor, with the last
ndim
dimensions being the image dimensions.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:
patches – Tensor of (overlapping) patches of shape:
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)
- Return type:
References
[1] https://stackoverflow.com/questions/64462917/view-as-windows-from-skimage-but-in-pytorch
[2] https://discuss.pytorch.org/t/patch-making-does-pytorch-have-anything-to-offer/33850/10