Skip to content

Instantly share code, notes, and snippets.

@glyg
Created September 6, 2021 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glyg/0fe53fea1c28185aab71d24746b1f9f1 to your computer and use it in GitHub Desktop.
Save glyg/0fe53fea1c28185aab71d24746b1f9f1 to your computer and use it in GitHub Desktop.
slices blocks from images
import numpy as np
img = np.random.poisson(size=(1024, 1024))
pad_x, pad_y = np.meshgrid(np.arange(-5, 5), np.arange(-5, 5))
cx = np.random.randint(0, img.shape[0], 12)
cy = np.random.randint(0, img.shape[0], 12)
xx = cx[:, None, None] + pad_x
yy = cy[:, None, None] + pad_y
blocks = img[xx, yy]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment