Skip to content

Commit d41f3bb

Browse files
2winszsdonghao
authored andcommitted
Update visualize.py (#543)
1 parent 1e54658 commit d41f3bb

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ numpy>=1.14,<1.15
33
progressbar2>=3.37,<3.38
44
scikit-image>=0.13,<0.14
55
scipy>=1.0,<1.1
6+
imageio>=2.3,<2.4

tensorlayer/visualize.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55
import numpy as np
6-
import scipy.misc # save/read image(s)
6+
import imageio # save/read image(s)
77

88
from . import _logging as logging
99
from . import prepro
@@ -44,7 +44,7 @@ def read_image(image, path=''):
4444
The image.
4545
4646
"""
47-
return scipy.misc.imread(os.path.join(path, image))
47+
return imageio.imread(os.path.join(path, image))
4848

4949

5050
def read_images(img_list, path='', n_threads=10, printable=True):
@@ -90,9 +90,9 @@ def save_image(image, image_path='_temp.png'):
9090
9191
"""
9292
try: # RGB
93-
scipy.misc.imsave(image_path, image)
93+
imageio.imwrite(image_path, image)
9494
except Exception: # Greyscale
95-
scipy.misc.imsave(image_path, image[:, :, 0])
95+
imageio.imwrite(image_path, image[:, :, 0])
9696

9797

9898
def save_images(images, size, image_path='_temp.png'):
@@ -108,11 +108,6 @@ def save_images(images, size, image_path='_temp.png'):
108108
image_path : str
109109
save path
110110
111-
Returns
112-
-------
113-
numpy.array
114-
The image.
115-
116111
Examples
117112
---------
118113
>>> images = np.random.rand(64, 100, 100, 3)
@@ -124,15 +119,15 @@ def save_images(images, size, image_path='_temp.png'):
124119

125120
def merge(images, size):
126121
h, w = images.shape[1], images.shape[2]
127-
img = np.zeros((h * size[0], w * size[1], 3))
122+
img = np.zeros((h * size[0], w * size[1], 3), dtype=images.dtype)
128123
for idx, image in enumerate(images):
129124
i = idx % size[1]
130125
j = idx // size[1]
131126
img[j * h:j * h + h, i * w:i * w + w, :] = image
132127
return img
133128

134129
def imsave(images, size, path):
135-
return scipy.misc.imsave(path, merge(images, size))
130+
return imageio.imwrite(path, merge(images, size))
136131

137132
if len(images) > size[0] * size[1]:
138133
raise AssertionError("number of images should be equal or less than size[0] * size[1] {}".format(len(images)))

0 commit comments

Comments
 (0)