Skip to content

Commit

Permalink
Remove cv2 dependency and use scipy.misc
Browse files Browse the repository at this point in the history
to read, resize, and save images.
  • Loading branch information
keunwoochoi committed Jan 11, 2016
1 parent cb13a33 commit ee6bad6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/neural_style_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'''

from __future__ import print_function
import cv2
from scipy.misc import imread, imresize, imsave
import numpy as np
from scipy.optimize import fmin_l_bfgs_b
import time
Expand Down Expand Up @@ -87,7 +87,7 @@

# util function to open, resize and format pictures into appropriate tensors
def preprocess_image(image_path):
im = cv2.resize(cv2.imread(image_path), (img_width, img_height))
im = imresize(imread(image_path), (img_width, img_height))
im = im.transpose((2, 0, 1))
im = np.expand_dims(im, axis=0)
return im
Expand Down Expand Up @@ -252,7 +252,7 @@ def eval_loss(x):
# save current generated image
im = deprocess_image(x.reshape((3, img_width, img_height)))
fname = result_prefix + '_at_iteration_%d.png' % i
cv2.imwrite(fname, im)
imsave(fname, im)
end_time = time.time()
print('Image saved as', fname)
print('Iteration %d completed in %ds' % (i, end_time - start_time))

0 comments on commit ee6bad6

Please sign in to comment.