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 52070a1

Browse files
2 parents 4d9d86e + 67be536 commit 52070a1

File tree

7 files changed

+51
-31
lines changed

7 files changed

+51
-31
lines changed

‎ActiveContour.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import cv2
1414
from scipy import ndimage
1515
import Image_preperation as prep
16+
import FileManager as fm
17+
import Image_preperation as prep
1618

1719
def calc_internal(p1,p2):
1820
if (np.array_equal(p1,p2)):
@@ -256,15 +258,15 @@ def resolution_downscale(img, resize):
256258
if __name__ == "__main__":
257259

258260
dir_radiographs = "_Data\Radiographs\*.tif"
259-
radiographs = ActiveShapeModel.load_files(dir_radiographs)
261+
radiographs = fm.load_files(dir_radiographs)
260262
radiograph = radiographs[0]
261263
init = np.load("initial_position.npy")
262264

263265
down_sample = 5
264266
tooth = init[0,4,:,:]/0.3
265267
#tooth = tooth/down_sample
266268

267-
radiograph_pre = pre_processing(radiograph)
269+
radiograph_pre = prep.pre_processing(radiograph)
268270
img = resolution_downscale(radiograph_pre,down_sample)
269271

270272
fig, ax = plt.subplots(figsize=(15, 15))
@@ -276,7 +278,7 @@ def resolution_downscale(img, resize):
276278
# In[196]:
277279

278280

279-
smooth = gaussian_smooth1(radiograph,10)
281+
smooth = prep.gaussian_smooth1(radiograph,10)
280282
grad = calc_external_img2(smooth)
281283
grad2 = calc_external_img2(radiograph)
282284
fig, ax = plt.subplots(figsize=(15, 15))
@@ -343,7 +345,7 @@ def resolution_downscale(img, resize):
343345
# In[141]:
344346

345347

346-
new_tooth = active_contour(tooth2, gausian(piece,1.5), 2, 2, 25)
348+
new_tooth = active_contour(tooth2, prep.gaussian(piece,1.5), 2, 2, 25)
347349
fig, ax = plt.subplots(figsize=(7, 7))
348350
plt.imshow(piece)
349351
plt.plot(new_tooth[:,0], new_tooth[:,1], 'ro', markersize=2)

‎ActiveShapeModel.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def active_shape_scale(img, tooth_points, pca_tooth, length, scale):
3232

3333
scaled_img , scaled_tooth_points = scaling(img, tooth_points, 1/scale)
3434
edge_img = prep.calc_external_img_active_contour(scaled_img)
35-
new_points = active_shape(edge_img, scaled_tooth_points, pca_tooth, length)
35+
new_points = active_shape(edge_img, scaled_tooth_points, pca_tooth, length,20)
3636
new_img, new_scaled_points = scaling(scaled_img, new_points, scale)
3737

3838
return new_scaled_points
@@ -44,6 +44,7 @@ def active_shape(edge_img, tooth_points, pca_tooth, length, alfa):
4444
b, pose_param = match.match_model_points(new_points, pca_tooth)
4545

4646
x = match.generate_model_point(b, pca_tooth)
47+
print(match.inv_transform(x.reshape(40,2),pose_param))
4748
return match.inv_transform(x.reshape(40,2),pose_param)
4849

4950
def active_shape_n_times(edge_img, tooth_points, pca_tooth, length,alfa, n_times):
@@ -110,53 +111,55 @@ def show_evolution(img, points_list):
110111
plt.show()
111112

112113

113-
# In[95]:
114+
# In[95]:
115+
114116

117+
points = active_shape_n_times(edge_img, tooth, pca_tooth, 5, 10,1)
118+
print(tooth.shape)
115119

116-
points = active_shape_n_times(edge_img, tooth, pca_tooth, 5, 10)
117120

118121

119-
# In[102]:
122+
# In[102]:
120123

121124

122-
new_points = points[1]
125+
new_points = points[1]
123126

124127

125-
# In[103]:
128+
# In[103]:
126129

127130

128-
fig, ax = plt.subplots(figsize=(15, 15))
129-
plt.imshow(radiograph)
130-
plt.plot(new_points[:,0], new_points[:,1], 'ro', markersize=1)
131-
plt.show()
131+
fig, ax = plt.subplots(figsize=(15, 15))
132+
plt.imshow(radiograph)
133+
plt.plot(new_points[:,0], new_points[:,1], 'ro', markersize=1)
134+
plt.show()
132135

133136

134-
# In[3]:
137+
# In[3]:
135138

136139

137-
img = fm.load_img_piece()
138-
tooth = fm.load_tooth_of_piece(4)
139-
landmarks = fm.load_landmarks_std()
140-
tooth_variations = landmarks[:,4]
141-
edge_img, pca_tooth = preperation(img, tooth_variations)
142-
fm.show_with_points(img, tooth)
140+
img = fm.load_img_piece()
141+
tooth = fm.load_tooth_of_piece(4)
142+
landmarks = fm.load_landmarks_std()
143+
tooth_variations = landmarks[:,4]
144+
edge_img, pca_tooth = preperation(img, tooth_variations)
145+
fm.show_with_points(img, tooth)
143146

144147

145-
# In[38]:
148+
# In[38]:
146149

147150

148-
#points_array = active_shape_scale_n_times(img, tooth, pca_tooth, 15, 4, 10)
149-
points_array = active_shape_n_times(edge_img, tooth, pca_tooth, 10, 20 ,9)
151+
#points_array = active_shape_scale_n_times(img, tooth, pca_tooth, 15, 4, 10)
152+
points_array = active_shape_n_times(edge_img, tooth, pca_tooth, 10, 20 ,9)
150153

151154

152-
# In[39]:
155+
# In[39]:
153156

154157

155-
show_evolution(img, points_array)
158+
show_evolution(img, points_array)
156159

157160

158-
# In[22]:
161+
# In[22]:
159162

160163

161-
points_array[0].shape
164+
points_array[0].shape
162165

‎Image_preperation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cv2
88
import numpy as np
99
import math
10+
import matplotlib
1011
from scipy import ndimage, signal
1112
import matplotlib.pyplot as plt
1213
import matplotlib
@@ -17,6 +18,7 @@
1718

1819
from skimage.util.dtype import dtype_range
1920
from skimage.util import img_as_ubyte
21+
from skimage.util import img_as_float
2022
from skimage.morphology import disk
2123
from skimage.filters import rank
2224
from skimage import exposure

‎Initial_pose_estimator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,5 @@ def active_contour_match(img, init):
183183
# In[19]:
184184

185185

186-
radiograph.shape
186+
# radiograph.shape
187187

‎Initialisation.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import FileManager
33
import numpy as np
44
import Initial_pose_estimator as ipe
5+
import ActiveShapeModel as asm
56

67
def showControls():
78
popup = np.ones((220,355), np.uint8)
@@ -13,11 +14,12 @@ def showControls():
1314
cv2.putText(popup,'Pageup/down: Bottom/top tooth distance',(10,55), font, 0.5,(240,255,255),1,cv2.LINE_AA)
1415
cv2.putText(popup,'" / ": Save current position to file',(10,100), font, 0.5,(240,255,255),1,cv2.LINE_AA)
1516
cv2.putText(popup,'" . ": Activate automatic initialisation',(10,115), font, 0.5,(240,255,255),1,cv2.LINE_AA)
16-
cv2.putText(popup,'" \' ": Activate automatic initialisation',(10,130), font, 0.5,(240,255,255),1,cv2.LINE_AA)
17+
cv2.putText(popup,'" \' ": Do segmentation',(10,130), font, 0.5,(240,255,255),1,cv2.LINE_AA)
1718
cv2.putText(popup,'" , ": Change to next radiograph',(10,145), font, 0.5,(240,255,255),1,cv2.LINE_AA)
1819
cv2.putText(popup,'" m ": Reset model',(10,160), font, 0.5,(240,255,255),1,cv2.LINE_AA)
1920
cv2.putText(popup,'" esc ": Close program',(10,175), font, 0.5,(240,255,255),1,cv2.LINE_AA)
2021
cv2.putText(popup,'" k ": Show/hide this popup',(10,190), font, 0.5,(240,255,255),1,cv2.LINE_AA)
22+
cv2.putText(popup,'" o ": ASM iteration',(10,205), font, 0.5,(240,255,255),1,cv2.LINE_AA)
2123
saved = cv2.namedWindow( "Controls", cv2.WINDOW_AUTOSIZE )
2224
cv2.imshow("Controls",popup)
2325

@@ -260,7 +262,18 @@ def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
260262
segmentation = cv2.bitwise_and(grays, grays, mask=mask)
261263
cv2.namedWindow("Segmentation",cv2.WINDOW_AUTOSIZE)
262264
cv2.imshow("Segmentation", segmentation)
263-
265+
elif k == 111:
266+
landmarks = FileManager.load_landmarks_std()
267+
grays = cv2.cvtColor(backdrop, cv2.COLOR_BGR2GRAY)
268+
tooth_variations = landmarks[:,0]
269+
tooth_points = np.empty((40,2))
270+
tooth_points = output[0,0,:,:]
271+
edge_img, pca_tooth = asm.preperation(grays, tooth_variations)
272+
points = asm.active_shape_scale(edge_img, tooth_points, pca_tooth, 5, scale)
273+
all_landmarks_std[0,0,:,:] = points
274+
drawTeeth(all_landmarks_std, backdrop, tooth_size, image_center, tooth_gap, top_bottom_separation)
275+
cv2.setMouseCallback('Radiograph',moveTeeth,(resized_image,all_landmarks_std,tooth_size,image_center,tooth_gap,top_bottom_separation))
276+
print("done")
264277
elif k == 47:
265278
# print(output)
266279
np.save("initial_position", output)

‎Report.docx

-891 KB
Binary file not shown.

‎initial_position.npy

0 Bytes
Binary file not shown.

0 commit comments

Comments
(0)

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