-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4. Final Crop.py
More file actions
68 lines (55 loc) · 2.44 KB
/
4. Final Crop.py
File metadata and controls
68 lines (55 loc) · 2.44 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
# %% Import modules
import sys
sys.path.append('/3D tissue visualization/') # <- Working directory where the Utils.py is located.
from Utils import *
# %% Load data
save_root = '/home/choiyoonho/Documents/HT/HE/Final_data/cropped'
save_ht = os.path.join(save_root, 'HT')
save_bf = os.path.join(save_root, 'BF')
save_he = os.path.join(save_root, 'HE')
save_fig= os.path.join(save_root, 'figs')
save_cell = os.path.join(save_root, 'Cell_instance')
os.makedirs(save_ht, exist_ok=True), os.makedirs(save_bf, exist_ok=True), os.makedirs(save_he, exist_ok=True)
os.makedirs(save_cell, exist_ok=True)
root = '/home/choiyoonho/Documents/HT/HE/Final_data/raw'
bf_paths = natsort.natsorted(glob(root+'/BF/*'))
ht_paths = natsort.natsorted(glob(root+'/HT/*'))
he_paths = natsort.natsorted(glob(root+'/HE/*'))
bf_paths = pop_insert(bf_paths, 0, 2)
ht_paths = pop_insert(ht_paths, 0, 2)
he_paths = pop_insert(he_paths, 0, 2)
# %% Load all images for final crop
bfs, hts, hes = [], [], []
for i, [bf_path, ht_path, he_path] in enumerate(zip(bf_paths, ht_paths, he_paths)):
print('{} - bf: {}, he: {}, ht: {}'.format(i, bf_path, ht_path, he_path))
name = bf_path.split('/')[-1].split('.')[0]
# Load HT transformed HE data
bf = tifffile.imread(bf_path) # HT scale
ht, _ = load_hdf5_with_attributes(ht_path) # HT scale
he = tifffile.imread(he_path) # HT scale
bfs.append(bf)
hts.append(ht)
hes.append(he)
# %% Final crop of HE with manual approach
plt.figure(figsize=(8, 12))
for i , [bf, ht, he] in enumerate(zip(bfs, hts, hes)):
plt.subplot(5,3,i*3+1)
plt.imshow(he[3000:5560,13000:15560])
# cv2.imwrite(os.path.join(save_fig, 'HE_'+str(i+1)+'.png'), cv2.cvtColor(he[3000:5560,13000:15560], cv2.COLOR_BGR2RGB))
plt.title('HE #{}'.format(i+1))
plt.axis('off')
plt.subplot(5,3,i*3+2)
plt.imshow(bf[3000:5560,13000:15560], cmap='gray')
# cv2.imwrite(os.path.join(save_fig, 'BF_'+ str(i+1) + '.png'), bf[3000:5560, 13000:15560])
plt.title('BF #{}'.format(i+1))
plt.axis('off')
plt.subplot(5, 3, i * 3 + 3)
temp_ht = ht[3000:5560, 13000:15560, 0].astype(np.uint8)
temp_ht = (temp_ht-temp_ht.mean())/temp_ht.std()
plt.imshow(temp_ht, cmap='gray')
# cv2.imwrite(os.path.join(save_fig, 'HT_' + str(i+1) + '_zscore.png'), temp_ht*255)
plt.title('HT #{}'.format(i+1))
plt.axis('off')
plt.suptitle('Serial section images for z axis')
plt.tight_layout()
plt.savefig(os.path.join(save_fig, 'Total_zxcore.png'))