forked from WarrenGreen/srcnn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
41 lines (32 loc) · 937 Bytes
/
util.py
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
36
37
38
39
40
41
import os
from pathlib import Path
import numpy as np
from PIL import Image
IMAGES_PATH = "images"
RAW_PATH = "raw"
TEST_PATH = "test"
TEST_LABELS_PATH = "test_labels"
TRAIN_PATH = "train"
TRAIN_LABELS_PATH = "train_labels"
ROWS, COLS, CHANNELS = (400, 400, 3)
BIT_DEPTH = 8
MAX_VAL = 2 ** 8 - 1
def clean_mkdir(path):
if Path(path).exists():
os.rmdir(path)
os.makedirs(path)
def load_data(x_path, y_path=None):
x, y = [], []
index = 0
for file in os.listdir(x_path):
index += 1
img = Image.open(x_path + file)
img_array = np.asarray(img, dtype="uint8")
img_array = img_array / (MAX_VAL * 1.0)
x.append(img_array)
if y_path is None:
img = Image.open(y_path + file)
img_array = np.asarray(img, dtype="uint8")
img_array = img_array / (MAX_VAL * 1.0)
y.append(img_array)
return np.array(x), np.array(y)