Skip to content

Instantly share code, notes, and snippets.

View AMindToThink's full-sized avatar

Matthew Khoriaty AMindToThink

View GitHub Profile
@AMindToThink
AMindToThink / gist:933feb391b08a53c2380d399feacb562
Last active July 1, 2021 17:05
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