-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_utils.py
More file actions
35 lines (26 loc) · 748 Bytes
/
Copy pathimage_utils.py
File metadata and controls
35 lines (26 loc) · 748 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
31
32
33
34
35
import imageio
from PIL import Image
import numpy as np
import os
def read_images(subdir: str):
"""
reads images from a given subdir
"""
imgs_subdir = os.curdir + subdir
out = []
for filename in os.listdir(imgs_subdir):
with open(imgs_subdir+filename, 'r'):
img = imageio.imread(imgs_subdir+filename)
out.append(np.asarray(img))
return np.asarray(out)
def sample_to_image(pred: np.ndarray, img_name: str):
"""
save generated image
"""
img_pixels = pred.copy()
img_pixels[img_pixels > 0.8] = 255
img_pixels[img_pixels <= 0.8] = 0
im = Image.fromarray(img_pixels)
if im.mode != 'RGB':
im = im.convert('RGB')
imageio.imsave(img_name, im)