-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocessing.py
54 lines (25 loc) · 933 Bytes
/
preprocessing.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
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
def normalize_scan(scan):
return (scan / 127.5) - 1.0
def preprocess_scan(scan_path):
# scan_path = str(scan_path)
img_names = [img for img in os.listdir(scan_path) if img.endswith('.png')]
scan = []
for img_name in img_names:
img_path = os.path.join(scan_path, img_name)
img = cv2.imread(img_path)
if len(img.shape) > 2:
img = img[:,:,0]
if (img.shape[0] != 128) or (img.shape[1] != 128):
img = cv2.resize(img, (128, 128))
scan.append(img)
scan = np.stack(scan, axis=-1)
scan = normalize_scan(scan)
return scan
def match_dims(scan):
scan = np.expand_dims(scan, axis=0)
scan = np.expand_dims(scan, axis=-1)
return scan