Skip to content

Instantly share code, notes, and snippets.

@AndrewBMartin
Last active June 21, 2019 16:18
Show Gist options
  • Save AndrewBMartin/75bd141e6467ba5a5467058ed5cce726 to your computer and use it in GitHub Desktop.
Save AndrewBMartin/75bd141e6467ba5a5467058ed5cce726 to your computer and use it in GitHub Desktop.
Read in images, transform them to a sprite image
import os
import glob
import cv2
LOG_DIR = "your-tensorboard-log-dir-here"
IMAGES_DIR = "your-images-dir-here"
IMAGE_SIZE = (64, 64)
SPRITES_FILE = os.path.join(LOG_DIR, "sprites.png")
# Max sprite size is 8192 x 8192 so this max samples makes visualization easy
MAX_NUMBER_SAMPLES = 8191
image_files = glob.glob(os.path.join(IMAGES_DIR, "*.png"))
img_data = []
for img in image_files[:MAX_NUMBER_SAMPLES]:
input_img = cv2.imread(img)
input_img_resize = cv2.resize(input_img, IMAGE_SIZE)
img_data.append(input_img_resize)
img_data = np.array(img_data)
sprite = create_sprite(img_data)
cv2.imwrite(SPRITES_FILE, sprite)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment