partition¶
- dnois.utils.partition(image: Tensor, n_patches: int | tuple[int, int], overlap: int | tuple[int, int] = 0, sequential: bool = False) list[Tensor] | list[list[Tensor]] ¶
Partition an image into patches, either overlapping or not.
Neighboring patches have an overlapping boundary of width
overlap
. Therefore, the size of single patch is:PH = (H + overlap[0]) / n_patches[0]
,PW = (W + overlap[1]) / n_patches[1]
.- Parameters:
image (Tensor) – One or more images of shape … x H x W.
n_patches (int | tuple[int, int]) – Number of patches in vertical and horizontal direction.
overlap (int | tuple[int, int]) – Overlapping width in vertical and horizontal direction.
sequential (bool) – Whether to arrange all patches into one dimension.
- Returns:
Image patches of shape
patches[0]
xpatches[1]
x … x PH x PW or (patches[0]
xpatches[1]
) x … x PH x PW, depending onsequential
wherein PH and PW are height and width of each patch, respectively.- Return type:
list[Tensor] if
sequential
isTrue
, list[list[Tensor]] otherwise.