Skip to content

Commit

Permalink
Replace deprecated functions in scipy.
Browse files Browse the repository at this point in the history
  • Loading branch information
divisiondeariza authored Dec 10, 2019
1 parent 7ca83ff commit d1b0c7f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import scipy.misc, numpy as np, os, sys
import imageio
from PIL import Image

def save_img(out_path, img):
img = np.clip(img, 0, 255).astype(np.uint8)
scipy.misc.imsave(out_path, img)
imageio.imwrite(out_path, img)

def scale_img(style_path, style_scale):
scale = float(style_scale)
o0, o1, o2 = scipy.misc.imread(style_path, mode='RGB').shape
o0, o1, o2 = imageio.imread(style_path, pilmode='RGB').shape
scale = float(style_scale)
new_shape = (int(o0 * scale), int(o1 * scale), o2)
style_target = _get_img(style_path, img_size=new_shape)
return style_target

def get_img(src, img_size=False):
img = scipy.misc.imread(src, mode='RGB') # misc.imresize(, (256, 256, 3))
img = imageio.imread(src, pilmode='RGB') # misc.imresize(, (256, 256, 3))
if not (len(img.shape) == 3 and img.shape[2] == 3):
img = np.dstack((img,img,img))
if img_size != False:
img = scipy.misc.imresize(img, img_size)
img = np.array(Image.fromarray(img).resize(img_size[:2]))
return img

def exists(p, msg):
Expand All @@ -30,4 +32,3 @@ def list_files(in_path):
break

return files

0 comments on commit d1b0c7f

Please sign in to comment.