-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
102 lines (70 loc) · 2.7 KB
/
Copy pathmain.py
File metadata and controls
102 lines (70 loc) · 2.7 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
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
import os, sys
import napari
import argparse
import numpy as np
import skimage as sk
import h5py
from ext_io import choose_tiff_files
from particle import Particle
def main(out_file, bbox_size = 60, plot = False):
file_paths = choose_tiff_files()
if len(file_paths) < 2:
print('At least 2 images are needed for strain calculations. Exiting...')
sys.exit(1)
all_samples = []
for file_path in file_paths:
vol = sk.io.imread(file_path, plugin='tifffile')
# Start the viewer
viewer = napari.Viewer()
image_layer = viewer.add_image(vol)
# Add an empty 3D Points layer (you can also load from existing data)
points_layer = viewer.add_points(
data=np.empty((0, 3)), # 3D points
ndim=3,
size=5,
face_color='lime',
name='Picked Points'
)
# Function to extract the points from the viewer
def extract_points():
points = points_layer.data # This is a NumPy array of shape (N, 3)
p1 = Particle(file_path, image=vol, position=points[0], bbox_size=bbox_size)
p2 = Particle(file_path, image=vol, position=points[1], bbox_size=bbox_size)
all_samples.append([p1, p2])
# for ii, point in enumerate(points_array):
# # print("Extracted Point:\n", point)
# p1 = Particle(file_path, image=vol, position=point, file='points.h5')
# all_samples.append(p)
# # print(p)
# viewer.close()
# return points
# Optional: Bind extraction to a key (e.g. press 'e' to extract)
@viewer.bind_key('e')
def on_key_e(viewer):
extract_points()
# print(points)
viewer.close()
napari.run()
image_names = []
z_coord_p1 = np.zeros(len(all_samples))
z_coord_p2 = np.zeros(len(all_samples))
for ii, [p1, p2] in enumerate(all_samples):
image_names.append(p1.image_name)
z_coord_p1[ii] = p1.centroid[0]
z_coord_p2[ii] = p2.centroid[0]
dz = z_coord_p2 - z_coord_p1
strains = (dz - dz[0])/dz[0]
with h5py.File(out_file, 'w') as hout:
hout['images'] = image_names
hout['p1z'] = z_coord_p1
hout['p2z'] = z_coord_p2
hout['dz'] = dz
hout['eps'] = strains
# print(strains)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--out_file', type=str)
parser.add_argument('-bb', '--bbox_size', type=int)
args = parser.parse_args()
# print(args.bbox_size, args.out_file )
main(out_file=args.out_file, bbox_size=args.bbox_size, plot=False)