-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprep_four_groups.py
More file actions
48 lines (45 loc) · 1.23 KB
/
prep_four_groups.py
File metadata and controls
48 lines (45 loc) · 1.23 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
import os
import sys
import copy
import numpy as np
def normalize(array):
mn = np.min(array)
mx = np.max(array)
array = (array - mn) / mx - mn
return array
def normalize_slicewise(arr):
shp = arr.shape
tally = 0
for n in range(shp[2]):
slc = arr[:,:,n]
mn = np.min(slc)
mx = np.max(slc)
if mx - mn == 0:
slc = slc + 1
else:
slc = (slc - mn) / (mx - mn)
arr[:,:,tally] = slc
tally = tally + 1
arr = arr[:,:,0:tally]
return arr
def get_four_groups_slices():
dirstr = '/home/realtime/project_deep/python'
os.chdir(dirstr)
os.listdir(dirstr)
all_slcs = np.load('all_slcs.npy')
print('Slices loaded')
print(all_slcs.shape)
all_slcs_r = np.real(copy.deepcopy(all_slcs))
print(np.max(all_slcs_r[:,:,0]))
print(np.min(all_slcs_r[:,:,0]))
print("nan check")
print(np.sum(np.isnan(all_slcs_r)))
all_slcs_dup = copy.deepcopy(all_slcs_r)
all_slcs_norm = normalize_slicewise(all_slcs_dup)
all_slcs_norm = np.moveaxis(all_slcs_norm, [0,1,2], [-2,-1,-3])
print(all_slcs_norm.shape)
n_slcs = all_slcs_norm.shape[0]
all_slcs_pad = np.zeros((n_slcs, 128, 128))
all_slcs_pad = all_slcs_pad.reshape(n_slcs, 128, 128, 1)
all_slcs_pad[:, 5:89, 5:105, 0] = all_slcs_norm
return all_slcs_pad