-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_for_figure.py
60 lines (40 loc) · 1.66 KB
/
export_for_figure.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
import os
import imageio.v3 as imageio
import h5py
from skimage.segmentation import find_boundaries
from scipy.ndimage import binary_dilation
def export():
image_folder = "/scratch-emmy/projects/nim00007/user-study/data/ground_truth/images"
pred_folder = "/scratch-emmy/projects/nim00007/user-study/predictions/test_images"
image_name = "VID532_H12_1_11d16h00m.tif"
out_folder = "./images/for_figure"
os.makedirs(out_folder, exist_ok=True)
im = imageio.imread(os.path.join(image_folder, image_name))
label_path = os.path.join(pred_folder, image_name.replace(".tif", ".h5"))
with h5py.File(label_path, "r") as f:
seg_vanilla = f["sam/vit_b"][:]
seg_ft = f["sam/v7/marei"][:]
imageio.imwrite(os.path.join(out_folder, "image.tif"), im, compression="zlib")
imageio.imwrite(os.path.join(out_folder, "seg_vanilla.tif"), seg_vanilla, compression="zlib")
imageio.imwrite(os.path.join(out_folder, "seg_ft.tif"), seg_ft, compression="zlib")
def _to_boundaries(seg, dilation=0):
boundaries = find_boundaries(seg)
if dilation > 0:
boundaries = binary_dilation(boundaries, iterations=dilation)
return boundaries
def make_figure():
import napari
im = imageio.imread("images/for_figure/image.tif")
seg_vanilla = imageio.imread("images/for_figure/seg_vanilla.tif")
bd_vanilla = _to_boundaries(seg_vanilla)
seg_ft = imageio.imread("images/for_figure/seg_ft.tif")
bd_ft = _to_boundaries(seg_ft)
v = napari.Viewer()
v.add_image(im)
v.add_labels(seg_vanilla)
v.add_labels(bd_vanilla)
v.add_labels(seg_ft)
v.add_labels(bd_ft)
napari.run()
# export()
make_figure()