Last active
September 11, 2020 11:28
-
-
Save wendeehsu/4bc6e74f9eddea7ae2d5c09216e5b3a6 to your computer and use it in GitHub Desktop.
load image and split into arrays
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
from os import listdir | |
from numpy import asarray | |
from numpy import vstack | |
from keras.preprocessing.image import img_to_array | |
from keras.preprocessing.image import load_img | |
from numpy import savez_compressed | |
def load_images(path, size=(256,512)): | |
src_list = list() | |
tar_list = list() | |
for filename in listdir(path): | |
# load and resize the image | |
pixels = load_img(path + filename, target_size=size) # images are in PIL formate | |
# convert to numpy array | |
pixels = img_to_array(pixels) | |
# split into colored and sketch. 256 comes from 512/2. The first part is colored while the rest is sketch | |
color_img, bw_img = pixels[:, :256], pixels[:, 256:] | |
src_list.append(bw_img) | |
tar_list.append(color_img) | |
return [asarray(src_list), asarray(tar_list)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment