forked from guojiyao/deep_fcn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetGraphObject.py
More file actions
72 lines (60 loc) · 2.1 KB
/
getGraphObject.py
File metadata and controls
72 lines (60 loc) · 2.1 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
from keras.utils import np_utils
def normalized(rgb):
#return rgb/255.0
norm=np.zeros((rgb.shape[0], rgb.shape[1], 3),np.float32)
b=rgb[:,:,0]
g=rgb[:,:,1]
r=rgb[:,:,2]
norm[:,:,0]=b/255.0
norm[:,:,1]=g/255.0
norm[:,:,2]=r/255.0
return norm
def one_hot_normalize(rgb):
# return one hot vector of mask
b=rgb[:,:,0]
label = b/255.0
#label = np_utils.to_categorical(label.flatten().astype(int), 2)
#label = label.reshape(rgb.shape[0],rgb.shape[1],2)
return label
def creatGraphObject():
x_train = []
y_train = []
x_test = []
y_test = []
x_shape = 400
y_shape = 400
for i in range(7000):
img = cv2.imread("/mnt/data/jiyao/masks/masks_img"+str(i+1)+".tif")
img = cv2.resize(img,(400,400))
img = one_hot_normalize(img)
img = np.stack([img])
#img = np.transpose(img,[2,0,1])
y_train.append(img)
for i in range(7000):
img = cv2.imread("/mnt/data/jiyao/tiles/tiles_img"+str(i+1)+".tif")
img = cv2.resize(img,(x_shape,y_shape))
img = normalized(img)
img = np.stack([img])
#img = np.transpose(img,[2,0,1])
x_train.append(img)
'''
for i in range(5000,6000):
img = cv2.imread("/mnt/data/jiyao/masks/masks_img"+str(i+1)+".tif")
img = cv2.resize(img,(x_shape,y_shape))
img = one_hot_normalize(img)
img = np.stack([img])
#img = np.transpose(img,[2,0,1])
y_test.append(img)
for i in range(5000,6000):
img = cv2.imread("/mnt/data/jiyao/tiles/tiles_img"+str(i+1)+".tif")
img = cv2.resize(img,(x_shape,y_shape))
img = normalized(img)
img = np.stack([img])
#img = np.transpose(img,[2,0,1])
x_test.append(img)
'''
return x_train, y_train, x_test, y_test