Skip to content

Instantly share code, notes, and snippets.

@AMindToThink
Last active July 1, 2021 17:05
Show Gist options
  • Save AMindToThink/933feb391b08a53c2380d399feacb562 to your computer and use it in GitHub Desktop.
Save AMindToThink/933feb391b08a53c2380d399feacb562 to your computer and use it in GitHub Desktop.
A method that turns a grid of images into a matrix of images. Input the image, the number of rows (numy), and the number of columns (numx). Get a specific image from the matrix with [row, column].
def matrixImages(image, numy, numx):
yFrac = image.shape[0] // numy
xFrac = image.shape[1] // numx
itemIcons = np.zeros((numy, numx, yFrac, xFrac, 3))
for i in range(numy):
for j in range(numx):
itemIcons[i, j] = image[i * yFrac : (i + 1) * yFrac, j * xFrac : (j + 1) * xFrac]/255
return itemIcons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment