-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookingatpatches.py
207 lines (183 loc) · 11.3 KB
/
lookingatpatches.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import matplotlib.pyplot as plt
import numpy as np
from read_rf import read
from scipy.signal import hilbert
def far_field_10patches(volume, focus):
focus = int(focus)
patches = np.concatenate((volume[focus-150-100: focus-150+100, 10:36, :], volume[focus-50-100: focus-50+100, 10:36, :],
volume[focus+50-100: focus+50+100, 10:36, :], volume[focus+150-100: focus+150+100, 10:36, :],
volume[focus + 250 - 100: focus + 250 + 100, 10:36, :],
volume[focus - 250 - 100: focus - 250 + 100, 10:36, :],
volume[focus + 350 - 100: focus + 350 + 100, 10:36, :],
volume[focus - 350 - 100: focus - 350 + 100, 10:36, :],
volume[focus + 450 - 100: focus + 450 + 100, 10:36, :],
volume[focus - 450 - 100: focus - 450 + 100, 10:36, :],
volume[focus-150-100: focus-150+100, 36:62, :], volume[focus-50-100: focus-50+100, 36:62, :],
volume[focus+50-100: focus+50+100, 36:62, :], volume[focus+150-100: focus+150+100, 36:62, :],
volume[focus + 250 - 100: focus + 250 + 100, 36:62, :],
volume[focus - 250 - 100: focus - 250 + 100, 36:62, :],
volume[focus + 350 - 100: focus + 350 + 100, 36:62, :],
volume[focus - 350 - 100: focus - 350 + 100, 36:62, :],
volume[focus + 450 - 100: focus + 450 + 100, 36:62, :],
volume[focus - 450 - 100: focus - 450 + 100, 36:62, :],
volume[focus-150-100: focus-150+100, 62:88, :], volume[focus-50-100: focus-50+100, 62:88, :],
volume[focus+50-100: focus+50+100, 62:88, :], volume[focus+150-100: focus+150+100, 62:88, :],
volume[focus + 250 - 100: focus + 250 + 100, 62:88, :],
volume[focus - 250 - 100: focus - 250 + 100, 62:88, :],
volume[focus + 350 - 100: focus + 350 + 100, 62:88, :],
volume[focus - 350 - 100: focus - 350 + 100, 62:88, :],
volume[focus + 450 - 100: focus + 450 + 100, 62:88, :],
volume[focus - 450 - 100: focus - 450 + 100, 62:88, :],
volume[focus-150-100: focus-150+100, 88:114, :], volume[focus-50-100: focus-50+100, 88:114, :],
volume[focus+50-100: focus+50+100, 88:114, :], volume[focus+150-100: focus+150+100, 88:114, :],
volume[focus + 250 - 100: focus + 250 + 100, 88:114, :],
volume[focus - 250 - 100: focus - 250 + 100, 88:114, :],
volume[focus + 350 - 100: focus + 350 + 100, 88:114, :],
volume[focus - 350 - 100: focus - 350 + 100, 88:114, :],
volume[focus + 450 - 100: focus + 450 + 100, 88:114, :],
volume[focus - 450 - 100: focus - 450 + 100, 88:114, :],
volume[focus-150-100: focus-150+100, 114:140, :], volume[focus-50-100: focus-50+100, 114:140, :],
volume[focus+50-100: focus+50+100, 114:140, :], volume[focus+150-100: focus+150+100, 114:140, :],
volume[focus + 250 - 100: focus + 250 + 100, 114:140, :],
volume[focus - 250 - 100: focus - 250 + 100, 114:140, :],
volume[focus + 350 - 100: focus + 350 + 100, 114:140, :],
volume[focus - 350 - 100: focus - 350 + 100, 114:140, :],
volume[focus + 450 - 100: focus + 450 + 100, 114:140, :],
volume[focus - 450 - 100: focus - 450 + 100, 114:140, :],
volume[focus-150-100: focus-150+100, 140:166, :], volume[focus-50-100: focus-50+100, 140:166, :],
volume[focus+50-100: focus+50+100, 140:166, :], volume[focus+150-100: focus+150+100, 140:166, :],
volume[focus + 250 - 100: focus + 250 + 100, 140:166, :],
volume[focus - 250 - 100: focus - 250 + 100, 140:166, :],
volume[focus + 350 - 100: focus + 350 + 100, 140:166, :],
volume[focus - 350 - 100: focus - 350 + 100, 140:166, :],
volume[focus + 450 - 100: focus + 450 + 100, 140:166, :],
volume[focus - 450 - 100: focus - 450 + 100, 140:166, :],
volume[focus-150-100: focus-150+100, 166:192, :], volume[focus-50-100: focus-50+100, 166:192, :],
volume[focus+50-100: focus+50+100, 166:192, :], volume[focus+150-100: focus+150+100, 166:192, :],
volume[focus + 250 - 100: focus + 250 + 100, 166:192, :],
volume[focus - 250 - 100: focus - 250 + 100, 166:192, :],
volume[focus + 350 - 100: focus + 350 + 100, 166:192, :],
volume[focus - 350 - 100: focus - 350 + 100, 166:192, :],
volume[focus + 450 - 100: focus + 450 + 100, 166:192, :],
volume[focus - 450 - 100: focus - 450 + 100, 166:192, :],
volume[focus-150-100: focus-150+100, 192:218, :], volume[focus-50-100: focus-50+100, 192:218, :],
volume[focus+50-100: focus+50+100, 192:218, :], volume[focus+150-100: focus+150+100, 192:218, :],
volume[focus + 250 - 100: focus + 250 + 100, 192:218, :],
volume[focus - 250 - 100: focus - 250 + 100, 192:218, :],
volume[focus + 350 - 100: focus + 350 + 100, 192:218, :],
volume[focus - 350 - 100: focus - 350 + 100, 192:218, :],
volume[focus + 450 - 100: focus + 450 + 100, 192:218, :],
volume[focus - 450 - 100: focus - 450 + 100, 192:218, :],
volume[focus-150-100: focus-150+100, 218:244, :], volume[focus-50-100: focus-50+100, 218:244, :],
volume[focus+50-100: focus+50+100, 218:244, :], volume[focus+150-100: focus+150+100, 218:244, :],
volume[focus + 250 - 100: focus + 250 + 100, 218:244, :],
volume[focus - 250 - 100: focus - 250 + 100, 218:244, :],
volume[focus + 350 - 100: focus + 350 + 100, 218:244, :],
volume[focus - 350 - 100: focus - 350 + 100, 218:244, :],
volume[focus + 450 - 100: focus + 450 + 100, 218:244, :],
volume[focus - 450 - 100: focus - 450 + 100, 218:244, :]), axis=2)
patches = np.swapaxes(patches, 1, 2)
patches = np.swapaxes(patches, 0, 1)
return patches
def dataset10_28_21_single_settings_10centerpatches_for_setsize(coef, num):
num = num//3
filepath1 = "//bi-fs4.beckman.illinois.edu/oelze/home/usoylu2/dataset/o10_28_21/phafr9fo2ir30o5d4.rf"
volume = read(filepath1)
depth, channels, frames = volume.shape
indices = np.random.permutation(volume.shape[2])
volume = volume[:, :, indices]
volume = volume[:, :, :num]
class1 = far_field_10patches(volume, coef * depth)
filepath1 = "//bi-fs4.beckman.illinois.edu/oelze/home/usoylu2/dataset/o10_28_21/ph40fr9fo2ir30o5d4.rf"
volume = read(filepath1)
depth, channels, frames = volume.shape
indices = np.random.permutation(volume.shape[2])
volume = volume[:, :, indices]
volume = volume[:, :, :num]
class2 = far_field_10patches(volume, coef * depth)
filepath1 = "//bi-fs4.beckman.illinois.edu/oelze/home/usoylu2/dataset/o10_28_21/ph50fr9fo2ir30o5d4.rf"
volume = read(filepath1)
depth, channels, frames = volume.shape
indices = np.random.permutation(volume.shape[2])
volume = volume[:, :, indices]
volume = volume[:, :, :num]
class3 = far_field_10patches(volume, coef * depth)
return np.concatenate((class1, class2, class3), axis=0),\
np.concatenate((np.zeros(class1.shape[0]), np.zeros(class2.shape[0])+1, np.zeros(class3.shape[0])+2))
def dataset10_28_21_single_settings_10centerpatches_for_setsize_train_test_split(coef, num):
x, y = dataset10_28_21_single_settings_10centerpatches_for_setsize(coef, num)
x_train = x[::3]
y_train = y[::3]
x_test = x[1::3]
y_test = y[1::3]
x_valid = x[2::3]
y_valid = y[2::3]
# x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=2/3, random_state=42)
return x_train, x_test, x_valid, y_train, y_test, y_valid
if __name__ == '__main__':
x_train, x_test, x_valid, y_train, y_test, y_valid = dataset10_28_21_single_settings_10centerpatches_for_setsize_train_test_split(2/4, 100)
print(x_train.shape, x_test.shape, x_valid.shape, y_train.shape, y_test.shape, y_valid.shape)
log = 20 * np.log10(np.abs(hilbert(x_train[10, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[10])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[30, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[30])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[40, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[40])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[100, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[100])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[900, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[1050])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[1050, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[1250])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[2900, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[2900])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()
log = 20 * np.log10(np.abs(hilbert(x_train[2950, :, :], axis=0)))
lognorm = log - np.amax(log)
print(y_train[2950])
plt.imshow(lognorm, extent=[0, 4, 4, 0], aspect='auto', cmap='gray', vmin=-60, vmax=0)
plt.colorbar()
plt.xlabel("mm")
plt.ylabel("mm")
plt.show()