Skip to content

Commit

Permalink
replace scipy.misc.imresize (suggested by @grochefort)
Browse files Browse the repository at this point in the history
  • Loading branch information
junyanz committed Aug 16, 2019
1 parent 27c4ec0 commit dca9002
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion scripts/eval_cityscapes/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def main():
label = CS.load_label(args.split, city, idx)
im_file = args.result_dir + '/' + idx + '_leftImg8bit.png'
im = np.array(Image.open(im_file))
# im = scipy.misc.imresize(im, (256, 256))
im = scipy.misc.imresize(im, (label.shape[1], label.shape[2]))
out = segrun(net, CS.preprocess(im))
hist_perframe += fast_hist(label.flatten(), out.flatten(), n_cl)
Expand Down
9 changes: 8 additions & 1 deletion util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ def diagnose_network(net, name='network'):
print(mean)


def save_image(image_numpy, image_path):
def save_image(image_numpy, image_path, aspect_ratio=1.0):
"""Save a numpy image to the disk
Parameters:
image_numpy (numpy array) -- input numpy array
image_path (str) -- the path of the image
"""

image_pil = Image.fromarray(image_numpy)
h, w, _ = image_numpy.shape

if aspect_ratio > 1.0:
image_pil = image_pil.resize((h, int(w * aspect_ratio)), Image.BICUBIC)
if aspect_ratio < 1.0:
image_pil = image_pil.resize((int(h / aspect_ratio), w), Image.BICUBIC)
image_pil.save(image_path)


Expand Down
10 changes: 2 additions & 8 deletions util/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from . import util, html
from subprocess import Popen, PIPE
from scipy.misc import imresize


if sys.version_info[0] == 2:
VisdomExceptionBase = Exception
Expand Down Expand Up @@ -36,13 +36,7 @@ def save_images(webpage, visuals, image_path, aspect_ratio=1.0, width=256):
im = util.tensor2im(im_data)
image_name = '%s_%s.png' % (name, label)
save_path = os.path.join(image_dir, image_name)
h, w, _ = im.shape
if aspect_ratio > 1.0:
im = imresize(im, (h, int(w * aspect_ratio)), interp='bicubic')
if aspect_ratio < 1.0:
im = imresize(im, (int(h / aspect_ratio), w), interp='bicubic')
util.save_image(im, save_path)

util.save_image(im, save_path, aspect_ratio=aspect_ratio)
ims.append(image_name)
txts.append(label)
links.append(image_name)
Expand Down

0 comments on commit dca9002

Please sign in to comment.