partition_padded¶
- dnois.utils.partition_padded(image: Tensor, n_patches: int | tuple[int, int], padding: int | tuple[int, int] = 0, mode: str = 'constant', value: float | int = 0, sequential: bool = False) list[Tensor] | list[list[Tensor]] ¶
Partition an image into patches, each of which is padded with pixels from neighbouring patches. Paddings of marginal patches depend on the parameters
mode
andvalue
.- 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.
padding (int | tuple[int, int]) – Padding width in vertical and horizontal direction.
mode (str) – See :func:
torch.nn.functional.pad
.value (int | float) – See :func:
torch.nn.functional.pad
.sequential (bool) – Whether to arrange all patches into one dimension.
- Returns:
Image patches of shape patches[0] x patches[1] x … x PH x PW or (patches[0] x patches[1]) x … x PH x PW, depending on
sequential
wherein PH and PW are height and width of each patch, respectively.- Return type:
list[Tensor] if
sequential
isTrue
, list[list[Tensor]] otherwise.