Last active
January 22, 2018 17:21
-
-
Save DmitryUlyanov/d475949007f43dca5d4b70bd6beeb0af to your computer and use it in GitHub Desktop.
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
import random | |
from PIL import Image | |
import glob | |
import numpy as np | |
def get_sample_grid_(paths, grid_w=4, grid_h=4, imsize_w=256, imsize_h=256): | |
imgs = [] | |
for p in paths: | |
imgs.append(np.array(Image.open(p).convert('RGB').resize([imsize_w,imsize_h]))) | |
rows = [] | |
for i in range(grid_h): | |
row = np.hstack(imgs[i*grid_w:(i+1)*grid_w]) | |
rows.append(row) | |
return Image.fromarray(np.vstack(rows)) | |
def get_sample_grid(dir_path, grid_w=4, grid_h=4, imsize_w=256, imsize_h=256): | |
paths = glob.glob(dir_path) | |
samples = random.sample(paths, grid_w * grid_h) | |
return get_sample_grid_(samples, grid_w, grid_h, imsize_w, imsize_h) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment