-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadBW.py
168 lines (109 loc) · 5.79 KB
/
loadBW.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 16 17:10:25 2017
@author: yzhang559
"""
import glob
from scipy import misc
import numpy as np
def load_train():
labels=[]
train_entity = np.empty((65536,0), "uint8")
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/0/*.PNG"):
a1=misc.imread(image_path)
if(len(a1.shape)==3):
a1=a1[:,:,0]
d1=np.reshape(a1,(1,65536))
train_entity = np.append(train_entity, d1, axis=0)
labels.append(0)
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/1/*.PNG"):
a2=misc.imread(image_path)
if(len(a2.shape)==3):
a2=a2[:,:,0]
d2=np.reshape(a2,(1,65536))
train_entity = np.append(train_entity, d2, axis=0)
labels.append(1)
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/2/*.PNG"):
a3=misc.imread(image_path)
if(len(a3.shape)==3):
a3=a3[:,:,0]
d3=np.reshape(a3,(1,65536))
train_entity = np.append(train_entity, d3, axis=0)
labels.append(2)
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/3/*.PNG"):
a4=misc.imread(image_path)
if(len(a4.shape)==3):
a4=a4[:,:,0]
d4=np.reshape(a4,(1,65536))
train_entity = np.append(train_entity, d4, axis=0)
labels.append(3)
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/4/*.PNG"):
a5=misc.imread(image_path)
if(len(a5.shape)==3):
a5=a5[:,:,0]
d5=np.reshape(a5,(1,65536))
train_entity = np.append(train_entity, d5, axis=0)
labels.append(4)
for image_path in glob.glob("/Users/Jenny/Desktop/imageResize/training-images/5/*.PNG"):
a6=misc.imread(image_path)
if(len(a6.shape)==3):
a6=a6[:,:,0]
d6=np.reshape(a6,(1,65536))
train_entity = np.append(train_entity, d6, axis=0)
labels.append(5)
train_label=np.asarray(labels)
train_arr=(train_entity,train_label)
print 'Train load Done!'
return train_arr
def load_test():
tlabels=[]
test_entity = np.empty((0,65536), "uint8")
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/0/*.PNG"):
ta1=misc.imread(image_path)
if(len(ta1.shape)==3):
ta1=ta1[:,:,0]
td1=np.reshape(ta1,(1,65536))
test_entity = np.append(test_entity, td1, axis=0)
tlabels.append(0)
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/1/*.PNG"):
ta2=misc.imread(image_path)
if(len(ta2.shape)==3):
ta2=ta2[:,:,0]
td2=np.reshape(ta2,(1,65536))
test_entity = np.append(test_entity, td2, axis=0)
tlabels.append(1)
print '1-------------------------------------'
print test_entity.shape
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/2/*.PNG"):
ta3=misc.imread(image_path)
if(len(ta3.shape)==3):
ta3=ta3[:,:,0]
td3=np.reshape(ta3,(1,65536))
test_entity = np.append(test_entity, td3, axis=0)
tlabels.append(2)
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/3/*.PNG"):
ta4=misc.imread(image_path)
if(len(ta4.shape)==3):
ta4=ta4[:,:,0]
td4=np.reshape(ta4,(1,65536))
test_entity = np.append(test_entity, td4, axis=0)
tlabels.append(3)
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/4/*.PNG"):
ta5=misc.imread(image_path)
if(len(ta5.shape)==3):
ta5=ta5[:,:,0]
td5=np.reshape(ta5,(1,65536))
test_entity = np.append(test_entity, td5, axis=0)
tlabels.append(4)
for image_path in glob.glob("/Users/Jenny/Desktop/BWimage/test/5/*.PNG"):
ta6=misc.imread(image_path)
if(len(ta6.shape)==3):
ta6=ta6[:,:,0]
td6=np.reshape(ta6,(1,65536))
test_entity = np.append(test_entity, td6, axis=0)
tlabels.append(5)
test_label=np.asarray(tlabels)
test_arr=(test_entity,test_label)
print 'Test load Done!'
return test_arr