-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5. Cell instance visualization.py
More file actions
58 lines (48 loc) · 2.14 KB
/
5. Cell instance visualization.py
File metadata and controls
58 lines (48 loc) · 2.14 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
# %% Import modules
import sys
sys.path.append('/home/choiyoonho/Documents/HT/3D tissue visualization/') # <- Working directory where the Utils.py is located.
from Utils import *
# %% Load data
root = '/home/choiyoonho/Documents/HT/HE/Final_data/cropped'
bf_paths = natsort.natsorted(glob(root+'/BF/*'))
ht_paths = natsort.natsorted(glob(root+'/HT/*'))
he_paths = natsort.natsorted(glob(root+'/HE/*'))
jsons = natsort.natsorted((glob('/home/choiyoonho/Documents/HT/HE/Final_data/cropped/Cell_instance/json/*')))
bf_paths = pop_insert(bf_paths, 0, 2)
ht_paths = pop_insert(ht_paths, 0, 2)
type_info = {
"0" : ["No-label", [0 , 0, 0]],
"1" : ["Neoplastic", [255, 0, 0]],
"2" : ["Inflamatory", [0, 0, 255]],
"3" : ["Connective", [0 , 255, 0]],
"4" : ["Necrosis", [255, 0, 0]],
"5" : ["No-label", [255, 0, 0]]
}
# plt.figure(figsize=(8, 12))
for i, [he_path, ht_path, json_path] in enumerate(zip(he_paths, ht_paths, jsons)):
he = cv2.imread(he_path)
he = cv2.cvtColor(he, cv2.COLOR_BGR2RGB)
ht, _ = load_hdf5_with_attributes(ht_path) # HT scale
plt.subplot(5, 3, i * 3 + 1)
plt.imshow(he)
plt.title('HE #{}'.format(i+1))
plt.axis('off')
plt.subplot(5, 3, i * 3 + 2)
bbox_list, centroid_list, contour_list, type_list = read_json(json_path)
coords_xmin, coords_ymin, coords_xmax, coords_ymax = 0, 0, he.shape[1], he.shape[0]
info_dict = get_info_dict(contour_list, coords_xmin, coords_ymin, coords_xmax, coords_ymax)
overlaid_output = visualize_instances_dict(he, info_dict, type_colour=type_info)
# cv2.imwrite(os.path.join(save_fig, 'HE_' + str(i + 1) + '_seg.png'), overlaid_output)
plt.imshow(overlaid_output)
plt.axis('off')
plt.title('Segmentation Overlay - #{}'.format(i+1))
#
plt.subplot(5, 3, i * 3 + 3)
temp_ht = (ht[:,:,0]-ht[:,:,0].min())/ht[:,:,0].max()
plt.imshow(temp_ht*255, cmap='gray')
plt.title('HT #{}'.format(i+1))
plt.axis('off')
plt.suptitle('Serial section images for z axis')
plt.tight_layout()
save_fig= os.path.join('/home/choiyoonho/Documents/HT/HE/Final_data/cropped', 'figs')
plt.savefig(os.path.join(save_fig, 'HE_seg_HT.png'))