src.utils.extract_patches module

src.utils.extract_patches module#

src.utils.extract_patches.extract_patches_numpy(arr, idx, jdx, r=10)[source]#

Efficiently extract local square patches centered at (idx, jdx) from a 2D array.

Out-of-bound regions are automatically filled with NaN.

Parameters:
  • arr (torch.Tensor) – Input 2D map tensor. Shape: (H, W)

  • idx (torch.LongTensor) – Row indices of the centers, corresponding to the map x-coordinate. Shape: (…, N).

  • jdx (torch.LongTensor) – Column indices of the centers, corresponding to the map y-coordinate. Shape must match idx.

  • r (int, optional) – Extraction radius. The window size is (2r+1)x(2r+1).

Returns:

Stacked extracted patches.

Shape: (…, N, 2r+1, 2r+1)

Return type:

torch.Tensor

src.utils.extract_patches.extract_patches_torch(arr, idx, jdx, r=10)[source]#
Parameters:
  • arr(H, W) input 2D tensor.

  • idx(…, l) center-coordinate LongTensors with any leading dimensions.

  • jdx(…, l) center-coordinate LongTensors with any leading dimensions.

  • r – Radius, default 10, so the window size is 21x21.

Returns:

A tensor of shape (…, l, 2r+1, 2r+1) with NaN-filled out-of-bound regions.