Overlapping control in Kornia extract_tensor_patches

Hi,
I’m using Kornia’s extract_tensor_patches to get image patches, and I want to control the overlap between them. I tried adjusting the stride, but it’s supposed to be equal to the window size, which isn’t giving me the desired result.

Any advice on how to manage overlapping without violating the stride-window size equality requirement?

Thanks!

I don’t think this is true as I can specify a smaller stride as seen here:

x = torch.arange(5*5).view(1, 1, 5, 5)
patches = kornia.contrib.extract_tensor_patches(x, window_size=(3, 3), stride=(1, 1))
print(x)
# tensor([[[[ 0,  1,  2,  3,  4],
#           [ 5,  6,  7,  8,  9],
#           [10, 11, 12, 13, 14],
#           [15, 16, 17, 18, 19],
#           [20, 21, 22, 23, 24]]]])
print(patches)
# tensor([[[[[ 0,  1,  2],
#            [ 5,  6,  7],
#            [10, 11, 12]]],


#          [[[ 1,  2,  3],
#            [ 6,  7,  8],
#            [11, 12, 13]]],


#          [[[ 2,  3,  4],
#            [ 7,  8,  9],
#            [12, 13, 14]]],


#          [[[ 5,  6,  7],
#            [10, 11, 12],
#            [15, 16, 17]]],


#          [[[ 6,  7,  8],
#            [11, 12, 13],
#            [16, 17, 18]]],


#          [[[ 7,  8,  9],
#            [12, 13, 14],
#            [17, 18, 19]]],


#          [[[10, 11, 12],
#            [15, 16, 17],
#            [20, 21, 22]]],


#          [[[11, 12, 13],
#            [16, 17, 18],
#            [21, 22, 23]]],


#          [[[12, 13, 14],
#            [17, 18, 19],
#            [22, 23, 24]]]]])
1 Like

It seems that the issue arises when I use “combine_tensor_patches.”

output= kornia.contrib.combine_tensor_patches(patches, original_size=tensor.shape[2], window_size=(3,3), stride=(1,1))
NotImplementedError: Only stride == window_size is supported. Got (1, 1) and (3, 3).Please feel free to drop a PR to Kornia Github.