-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (25 loc) · 908 Bytes
/
utils.py
File metadata and controls
32 lines (25 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
def show_image(images, nrow, ncolumn):
fig = plt.figure()
npimg = images.add(1.0).mul(127.5).numpy()[0,0,:,:,:]
for i in xrange(nrow*ncolumn):
fig.add_subplot(nrow, ncolumn, i + 1)
img = npimg[:, :, i]
plt.imshow(img)
plt.show()
def save_image(images, nrow, ncolumn, filename):
image_size = images.size(2)
figure = np.zeros((nrow * image_size, ncolumn * image_size))
npimg = images.add(1.0).mul(127.5).numpy()[0, 0, :, :, :]
for i in xrange(nrow * ncolumn):
img = npimg[:, :, i]
h1=(i // ncolumn) * image_size
h2=(i // ncolumn + 1)*image_size
w1=(i % ncolumn) * image_size
w2=(i % ncolumn + 1)*image_size
figure[h1:h2, w1:w2] = img
figure = figure.astype(np.uint8)
im = Image.fromarray(figure)
im.save(filename)