Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Create images patches with overlap using torch.unfold

$
0
0

I would like to split an images into smaller images of 1024x1024. I would like to have an overlap of 100 pixels in the top/bottom and left/right of the patches.

[enter image description here]

I am using padding and torch.unfold to create even sized patches.

def create_patches(image, patch_size):    # Pad right and bottom to fit patch_size    padding_right = patch_size - image.shape[2]%patch_size    padding_bottom = patch_size - image.shape[1]%patch_size    image = F.pad(image, (0, 0, padding_right, padding_bottom))    return image.unfold(0, 3, 3).unfold(1, patch_size, patch_size).unfold(2, patch_size, patch_size)

How can I make the patches to overlap?


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>