Created
January 4, 2018 07:31
-
-
Save ArnoutDevos/e2e3a1734b81930f0719138bd156fd6b 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
# Output folder for the images. | |
OUTPUT_DIR = 'output/' | |
# Style image to use. | |
STYLE_IMAGE = 'images/muse.jpg' | |
# Content image to use. | |
CONTENT_IMAGE = 'images/trojan_shrine.jpg' | |
# Image dimensions constants. | |
IMAGE_WIDTH = 640 | |
IMAGE_HEIGHT = 480 | |
COLOR_CHANNELS = 3 | |
def load_image(path): | |
image_raw = scipy.misc.imread(path) | |
# Resize the image for convnet input and add an extra dimension | |
image_raw = scipy.misc.imresize(image_raw, (IMAGE_HEIGHT, IMAGE_WIDTH)) | |
# Input to the VGG model expects the mean to be subtracted. | |
image = (image_raw - MEAN_VALUES) | |
return [image_raw, image] | |
def recover_image(image): | |
image_raw = image + MEAN_VALUES | |
image_raw = np.clip(image_raw, 0, 255).astype('uint8') | |
return image_raw | |
def save_image(path, image): | |
# Output should add back the mean. | |
image = recover_image(image) | |
scipy.misc.imsave(path, image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment