Created
February 28, 2018 09:03
-
-
Save hlzz/ba6da6e692beceb4da8b4d5387a8eacc to your computer and use it in GitHub Desktop.
Generate sprite images for tensorboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from PIL import Image | |
import math | |
test_image_list = '/home/tianwei/Data/sfm_data/test_image_list' # path to the image list | |
with open(test_image_list, 'r') as f: | |
test_images = f.readlines() | |
test_images = map(str.strip, test_images) | |
grid = int(math.sqrt(len(test_images))) + 1 | |
image_height = int(8192 / grid) # tensorboard supports sprite images up to 8192 x 8192 | |
image_width = int(8192 / grid) | |
big_image = Image.new( | |
mode='RGBA', | |
size=(image_width * grid, image_height * grid), | |
color=(0,0,0,0)) # fully transparent | |
for i in range(len(test_images)): | |
row = i / grid | |
col = i % grid | |
img = Image.open(test_images[i]) | |
img = img.resize((image_height, image_width), Image.ANTIALIAS) | |
row_loc = row * image_height | |
col_loc = col * image_width | |
big_image.paste(img, (col_loc, row_loc)) # NOTE: the order is reverse due to PIL saving | |
print(row_loc, col_loc) | |
big_image.save('sprite_image.jpg', transparency=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked for me.
changed: