-
Notifications
You must be signed in to change notification settings - Fork 0
/
final_generate_mean_images
184 lines (138 loc) · 3.7 KB
/
final_generate_mean_images
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
###
import glob
import cv2
images = [cv2.imread(file) for file in glob.glob("/content/drive/My Drive/trainn/train/Covid/*.png")]
y1=[]
for i in range(1,100):
gray1=cv2.resize(images[i],(224,224))
img_gray1 = cv2.cvtColor(gray1, cv2.COLOR_BGR2GRAY)
y1.append(img_gray1)
y2=[]
for i in range(100,199):
gray2=cv2.resize(images[i],(224,224))
img_gray2 = cv2.cvtColor(gray2, cv2.COLOR_BGR2GRAY)
y2.append(img_gray2)
y3=[]
for i in range(199,300):
gray3=cv2.resize(images[i],(224,224))
img_gray3 = cv2.cvtColor(gray3, cv2.COLOR_BGR2GRAY)
y3.append(img_gray3)
####
import cv2
images1 = [cv2.imread(file) for file in glob.glob("/content/drive/My Drive/trainn/train/Non-Covid/*.png")]
y4=[]
for i in range(1,100):
gray4=cv2.resize(images1[i],(224,224))
img_gray4 = cv2.cvtColor(gray4, cv2.COLOR_BGR2GRAY)
y4.append(img_gray4)
y5=[]
for i in range(100,199):
gray5=cv2.resize(images1[i],(224,224))
img_gray5 = cv2.cvtColor(gray5, cv2.COLOR_BGR2GRAY)
y5.append(img_gray5)
y6=[]
for i in range(199,300):
gray6=cv2.resize(images1[i],(224,224))
img_gray6 = cv2.cvtColor(gray6, cv2.COLOR_BGR2GRAY)
y6.append(img_gray6)
y1=np.array(y1)
y2=np.array(y2)
y3=np.array(y3)
y4=np.array(y4)
y5=np.array(y5)
y6=np.array(y6)
aaa=np.concatenate((y1,y2,y3,y4,y5,y6), axis=0)
from numpy import genfromtxt
ou = genfromtxt('/content/drive/My Drive/5_probs.csv', delimiter=',')
ou=ou[1:,1:]
ou=np.nan_to_num(ou)
#for the first cluster
sk1=[]
for i in range (0,598):
skata1=aaa[i]*ou[i,0]
sk1.append(skata1)
#for the second cluster
sk2=[]
for i in range (0,598):
skata2=aaa[i]*ou[i,1]
sk2.append(skata2)
sk3=[]
for i in range (0,598):
skata3=aaa[i]*ou[i,2]
sk3.append(skata3)
sk4=[]
for i in range (0,598):
skata4=aaa[i]*ou[i,3]
sk4.append(skata4)
sk5=[]
for i in range (0,598):
skata5=aaa[i]*ou[i,4]
sk5.append(skata5)
sk6=[]
for i in range (0,598):
skata6=aaa[i]*ou[i,5]
sk6.append(skata6)
sk7=[]
for i in range (0,598):
skata7=aaa[i]*ou[i,6]
sk7.append(skata7)
sk8=[]
for i in range (0,598):
skata8=aaa[i]*ou[i,7]
sk8.append(skata8)
sk9=[]
for i in range (0,598):
skata9=aaa[i]*ou[i,8]
sk9.append(skata9)
imgray1=sum(sk1)/198
img1 = cv2.merge((imgray1,imgray1,imgray1))
imgray2=sum(sk2)/198
img2 = cv2.merge((imgray2,imgray2,imgray2))
imgray3=sum(sk3)/198
img3 = cv2.merge((imgray3,imgray3,imgray3))
imgray4=sum(sk4)/198
img4 = cv2.merge((imgray4,imgray4,imgray4))
imgray5=sum(sk5)/198
img5 = cv2.merge((imgray5,imgray5,imgray5))
imgray6=sum(sk6)/198
img6 = cv2.merge((imgray6,imgray6,imgray6))
imgray7=sum(sk7)/198
img7 = cv2.merge((imgray7,imgray7,imgray7))
imgray8=sum(sk8)/198
img8 = cv2.merge((imgray8,imgray8,imgray8))
imgray9=sum(sk9)/198
img9 = cv2.merge((imgray9,imgray9,imgray9))
plt.imshow((img1 * 255).astype(np.uint8))
plt.imshow(imgray1)
plt.imshow((img2 * 255).astype(np.uint8))
plt.imshow(imgray2)
plt.imshow((img3 * 255).astype(np.uint8))
plt.imshow(imgray3)
#plot them
plt.imshow((img1 * 255).astype(np.uint8))
plt.imshow(imgray1)
plt.imshow((img2 * 255).astype(np.uint8))
plt.imshow(imgray2)
plt.imshow((img3 * 255).astype(np.uint8))
plt.imshow(imgray3)
plt.imshow((img4 * 255).astype(np.uint8))
plt.imshow(imgray4)
plt.imshow((img5 * 255).astype(np.uint8))
plt.imshow(imgray5)
plt.imshow((img6 * 255).astype(np.uint8))
plt.imshow(imgray6)
plt.imshow((img7 * 255).astype(np.uint8))
plt.imshow(imgray7)
plt.imshow((img8 * 255).astype(np.uint8))
plt.imshow(imgray8)
plt.imshow((img9 * 255).astype(np.uint8))
plt.imshow(imgray9)
#calculate the comparative mean class (covid or non covid)
covid=ou[1:299,1]*[1]
covid=ou[1:299,2]*[1]
...
covid=ou[1:299,7]*[1]
non_covid=ou[299:598,6]*[1]
...non_covid=ou[299:598,6]*[1]
sum(covid)/598
sum(non_covid)/598