-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbranch_detec.py
More file actions
58 lines (39 loc) · 1.61 KB
/
branch_detec.py
File metadata and controls
58 lines (39 loc) · 1.61 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
import numpy as np
from sklearn.preprocessing import normalize
angel_thresh = 40
# ct iamge array
ct_arr = np.load('ct_arr.npy')
rays = normalize(np.array([[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1],
[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,1],[0,1,-1],[0,1,0],[0,1,1]]))
rays_label = np.zeros(17)
radius = 1
p1,p2 = np.array([4,7,8]),np.array([2,6,7])
# p1: last point; p2: current point; radius: radius at p2
def bran_detec(p1, p2, rays, radius):
direc = p2-p1
lenth = np.linalg.norm(direc) # length normalize
norm_direc = direc/lenth # direc normalize
offset = norm_direc-np.array([1,0,0])
rays += offset
rays *= radius*4
rays_end = rays+p2
set1, set2 = ray_set(rays_end)
return np.mean(set1, axis=0), np.mean(set2, axis=0)
def cal_angle(v1,v2):
dot_product = np.dot(v1,v2)
arccos = np.arccos(dot_product/(np.linalg.norm(v1)*np.linalg.norm(v2)))
angle = np.degrees(arccos)
return angle
def ray_set(rays_end):
set1 = np.zeros((0,3))
set2 = np.zeros((0,3))
for i in range(len(rays_end)):
if rays_end[i] >= 200:
base= rays_end[i]
for j in range(i, len(rays_end)):
if rays_end[j]>=200 and cal_angle(base, rays_label[j]) >= angel_thresh:
set2 = np.append(set2, rays_end[j], axis=0)
elif rays_end[j]>=200 and cal_angle(base, rays_label[j]) < angel_thresh:
set1 = np.append(set1, rays_end[j], axis=0)
break
return set1, set2