Created
June 22, 2019 00:24
-
-
Save makeyourownalgorithmicart/2e866501ed861af2bccfb756b6879f23 to your computer and use it in GitHub Desktop.
ferg_db to hdf5
This file contains hidden or 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
# (c) Tariq Rashid 2019 | |
# GPL v2 | |
import h5py | |
import imageio | |
import os | |
import PIL.Image | |
import numpy | |
# | |
with h5py.File('fergdb/fergdb_64.h5py', 'w') as hf: | |
count = 1 | |
for emotion in emotions: | |
for name in names: | |
dirname = 'fergdb/' + name+ '/' + name + '_' + emotion | |
with os.scandir(dirname) as entries: | |
for entry in entries: | |
if entry.name.endswith("png"): | |
#print(entry.path) | |
img = imageio.imread(entry.path) | |
# resize | |
img = PIL.Image.fromarray(img).resize((64,64), resample=PIL.Image.BILINEAR) | |
# remove alpha and use white background | |
img2 = PIL.Image.new("RGB", img.size, "WHITE") | |
img2.paste(img, (0, 0), img) | |
img2 = numpy.array(img2) | |
hf.create_dataset(entry.name, data=img2, compression="gzip", compression_opts=9) | |
if (count%1000 == 0): | |
print(count, img2.shape) | |
count += 1 | |
pass | |
pass | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
converts images to hdf5, includes image resizing too