Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4d9d86e

Browse files
fit function angle fix
better image preperation filemanager some update
1 parent 26e25bf commit 4d9d86e

13 files changed

+1230
-953
lines changed

‎.ipynb_checkpoints/ActiveContour-checkpoint.ipynb

Lines changed: 47 additions & 580 deletions
Large diffs are not rendered by default.

‎.ipynb_checkpoints/FileManager-checkpoint.ipynb

Lines changed: 47 additions & 11 deletions
Large diffs are not rendered by default.

‎.ipynb_checkpoints/FitFunction-checkpoint.ipynb

Lines changed: 228 additions & 53 deletions
Large diffs are not rendered by default.

‎.ipynb_checkpoints/Image_preperation-checkpoint.ipynb

Lines changed: 195 additions & 85 deletions
Large diffs are not rendered by default.

‎ActiveContour.ipynb

Lines changed: 101 additions & 38 deletions
Large diffs are not rendered by default.

‎ActiveFitContour.ipynb

Lines changed: 124 additions & 19 deletions
Large diffs are not rendered by default.

‎FileManager.ipynb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 4,
5+
"execution_count": 3,
66
"metadata": {},
77
"outputs": [],
88
"source": [
@@ -12,6 +12,12 @@
1212
"import matplotlib.pyplot as plt\n",
1313
"from scipy.spatial import procrustes\n",
1414
"import numpy as np\n",
15+
"import Image_preperation as prep\n",
16+
"\n",
17+
"def pre_pocess(img):\n",
18+
" median = prep.median_filter(img)\n",
19+
" contrast = prep.contrast_stretching(median)\n",
20+
" return contrast\n",
1521
"\n",
1622
"def resolution_scale(img, points, scale):\n",
1723
" new_points = resolution_scale_points(points, scale)\n",
@@ -46,7 +52,8 @@
4652
"\n",
4753
"def load_img_piece():\n",
4854
" img = load_radiograph()\n",
49-
" return img[700:1300,1200:1800]\n",
55+
" new_img = pre_pocess(img)\n",
56+
" return new_img[700:1300,1200:1800]\n",
5057
"\n",
5158
"def show_with_points(img, points):\n",
5259
" fig, ax = plt.subplots(figsize=(7, 7))\n",

‎FileManager.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# coding: utf-8
33

4-
# In[2]:
4+
# In[3]:
55

66

77
import os
@@ -10,6 +10,12 @@
1010
import matplotlib.pyplot as plt
1111
from scipy.spatial import procrustes
1212
import numpy as np
13+
import Image_preperation as prep
14+
15+
def pre_pocess(img):
16+
median = prep.median_filter(img)
17+
contrast = prep.contrast_stretching(median)
18+
return contrast
1319

1420
def resolution_scale(img, points, scale):
1521
new_points = resolution_scale_points(points, scale)
@@ -35,16 +41,17 @@ def load_tooth(i):
3541
init = np.load("initial_position.npy")
3642
return init[0,i,:,:]/0.3
3743

38-
def load_tooth_of_piece(i=4):
39-
tooth = load_tooth(i)
44+
def load_tooth_of_piece():
45+
tooth = load_tooth(4)
4046
tooth_of_piece = tooth
4147
tooth_of_piece[:,0]=tooth[:,0]-1200
4248
tooth_of_piece[:,1]=tooth[:,1]-700
4349
return tooth_of_piece
4450

4551
def load_img_piece():
4652
img = load_radiograph()
47-
return img[700:1300,1200:1800]
53+
new_img = pre_pocess(img)
54+
return new_img[700:1300,1200:1800]
4855

4956
def show_with_points(img, points):
5057
fig, ax = plt.subplots(figsize=(7, 7))
@@ -142,13 +149,15 @@ def show_teeth_points(landmarks):
142149
plt.figure()
143150
n = len(landmarks)
144151
hn = int(n/2)
152+
fig, ax = plt.subplots(figsize=(15, 7))
145153

146154
print('Showing Teeth Landmarks')
147155

148156
for i, landmark in enumerate(landmarks):
149157
plt.subplot(2, hn, i+1)
150-
plt.xticks(())
151-
plt.yticks(())
158+
if(i!=hn):
159+
plt.xticks(())
160+
plt.yticks(())
152161
plt.plot(landmark[:,0], landmark[:,1], 'ro')
153162

154163
plt.show()
@@ -164,7 +173,7 @@ def load_segmentations():
164173
return load_files(dir_segmentations)
165174

166175

167-
# In[9]:
176+
# In[5]:
168177

169178

170179
if __name__ == "__main__":

‎FitFunction.ipynb

Lines changed: 135 additions & 23 deletions
Large diffs are not rendered by default.

‎FitFunction.py

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# coding: utf-8
33

4-
# In[7]:
4+
# In[2]:
55

66

77
import Image_preperation as prep
@@ -68,13 +68,50 @@ def is_vertical(a,b,c):
6868
def is_equal(b_proj , b):
6969
return np.array_equal(b_proj, b)
7070

71+
7172
def get_normal_angle(a,b,c):
7273
if( is_horizontal(a,b,c) ):
7374
return math.pi/2
7475
if( is_vertical(a,b,c) ):
7576
return 0
7677

7778
b_proj = project_on(b, a,c)
79+
80+
#is linear
81+
if(is_equal(b_proj , b)):
82+
83+
c_norm = np.add(c,[2,0])
84+
if(is_equal(a,b)):
85+
a_corr = np.add(a,[-5,0])
86+
a_proj = project_on(a_corr, b ,c)
87+
rad = calc_angle(a_proj,b,c_norm)
88+
else:
89+
rad = calc_angle(a,b,c_norm)
90+
91+
#not linear
92+
else:
93+
b_norm = np.add(b, [2,0])
94+
rad = calc_angle(b_proj, b, b_norm)
95+
96+
#rad given back relative to x-axis
97+
if( b_norm[0] > b[0]):
98+
if (b_proj[1] > b_norm[1]):
99+
return rad
100+
else:
101+
return -rad
102+
else:
103+
if( b_proj[1] > b_norm[1]):
104+
return -rad
105+
else:
106+
return rad
107+
108+
def get_normal_angle2(a,b,c):
109+
if( is_horizontal(a,b,c) ):
110+
return math.pi/2
111+
if( is_vertical(a,b,c) ):
112+
return 0
113+
114+
b_proj = project_on(b, a,c)
78115

79116
if(is_equal(b_proj , b)):
80117
c_norm = np.add(c,[2,0])
@@ -86,7 +123,7 @@ def get_normal_angle(a,b,c):
86123

87124
b_norm = np.add(b, [2,0])
88125

89-
return calc_angle(b, b_proj, b_norm)
126+
return calc_angle(b_proj, b, b_norm)
90127

91128
def project_on(x, a,c):
92129
n = np.subtract(a, c)
@@ -214,7 +251,7 @@ def test_normal_on_edge():
214251

215252

216253

217-
# In[14]:
254+
# In[3]:
218255

219256

220257
if __name__ == "__main__":
@@ -232,6 +269,7 @@ def test_normal_on_edge():
232269
new_points[:,1]=points[:,1]-300
233270

234271
a,b,c = new_points[0:3]
272+
235273
rad = get_normal_angle(a,b,c)
236274
p1 = get_point_at_distance(b, 20, rad)
237275
p2 = get_point_at_distance(b, -20, rad)
@@ -240,17 +278,17 @@ def test_normal_on_edge():
240278
p2 = np.array(p2,dtype=int)
241279
make_line(img_copy, p1,p2)
242280

243-
visualize_points = new_points.take([38,39,0,1,2,3],axis=0)
281+
visualize_points = new_points.take([38,39,0,1,2,3,4,5],axis=0)
244282
proj = project_on(b, a,c)
245-
visualize_points = np.append(visualize_points,proj).reshape(-1,2)
283+
#new_visualize_points = np.append(visualize_points,proj).reshape(-1,2)
246284

247285
show_with_points(img_copy,visualize_points)
248286

249287
edges = get_points_on_angle_normal(b, rad, 20)
250-
edge_img = prep.edge_detection_high(new_pice)
288+
edge_img = prep.sobel(new_pice)
251289
strength = edge_strength_at_points(edges ,edge_img)
252290

253-
show_with_points(new_pice,edges)
291+
#show_with_points(new_pice,np.append(edges,visualize_points).reshape(-1,2))
254292

255293
fig, ax = plt.subplots(figsize=(7, 7))
256294
plt.plot(np.arange(-20,21),strength)
@@ -274,3 +312,31 @@ def test_normal_on_edge():
274312
# new_points, error = fit_measure(tooth, 30, edge_img)
275313
# fm.show_with_points(piece, new_points)
276314

315+
316+
# In[11]:
317+
318+
319+
math.degrees(rad)
320+
321+
322+
# In[14]:
323+
324+
325+
math.degrees(calc_angle(c,b,a))
326+
327+
328+
# In[4]:
329+
330+
331+
edge_img = prep.calc_external_img_active_contour(new_pice)
332+
p = strongest_edge_point_on_normal(a,b,c,20, edge_img)
333+
show_with_points(edge_img,np.append(visualize_points,p).reshape(-1,2))
334+
335+
336+
# In[8]:
337+
338+
339+
edge_img = prep.canny(new_pice)
340+
p = strongest_edge_point_on_normal(a,b,c,20, edge_img)
341+
show_with_points(edge_img,np.append(visualize_points,p).reshape(-1,2))
342+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /