@@ -174,6 +174,16 @@ def drawTeeth(landmarks,backdrop,tooth_size,image_center,tooth_gap,top_bottom_se
174
174
cv2 .circle (backdrop ,(x ,y ),1 ,(255 ,255 ,255 ),- 1 )
175
175
cv2 .imshow ("Radiograph" ,backdrop )
176
176
177
+ def tempShow (text = "Hello World" ):
178
+ popup = np .ones ((50 ,330 ), np .uint8 )
179
+ font = cv2 .FONT_HERSHEY_SIMPLEX
180
+ cv2 .putText (popup ,text ,(10 ,25 ), font , 0.5 ,(240 ,255 ,255 ),1 ,cv2 .LINE_AA )
181
+ saved = cv2 .namedWindow ( "Saved" , cv2 .WINDOW_AUTOSIZE )
182
+ cv2 .imshow ("Saved" ,popup )
183
+ cv2 .waitKey (2500 )
184
+ cv2 .destroyWindow ("Saved" )
185
+
186
+
177
187
def InitializeASM (directory = "_Data\\ Radiographs\\ *.tif" ):
178
188
dir_radiographs = directory
179
189
radiographs = FileManager .load_files (dir_radiographs )
@@ -188,9 +198,14 @@ def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
188
198
global size
189
199
global scale
190
200
global output
201
+ global currentImage
191
202
showpopup = 1
192
203
cv2 .setMouseCallback ('Radiograph' ,moveTeeth ,(resized_image ,all_landmarks_std ))
193
204
205
+ tempShow ("Calculating Edges + PCA..." )
206
+ grays = cv2 .cvtColor (resized_image , cv2 .COLOR_BGR2GRAY )
207
+ edge_img , pca_teeth = asm .preperation_all (grays , all_landmarks_std )
208
+ tempShow ("Calculating Edges + PCA : DONE!" )
194
209
195
210
196
211
loop = 1
@@ -271,21 +286,62 @@ def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
271
286
segmentation = cv2 .bitwise_and (grays , grays , mask = mask )
272
287
cv2 .namedWindow ("Segmentation" ,cv2 .WINDOW_AUTOSIZE )
273
288
cv2 .imshow ("Segmentation" , segmentation )
274
- elif k == 111 :
289
+ elif k == 92 :
290
+ grays = cv2 .cvtColor (backdrop , cv2 .COLOR_BGR2GRAY )
291
+ mask = np .zeros (grays .shape , np .uint8 )
292
+ for i in range (0 ,8 ):
293
+ test = output [0 ,i ,:,:].astype (np .int32 )
294
+ cv2 .fillConvexPoly (mask , test ,(255 ,255 ,255 ))
295
+ segmentation = cv2 .bitwise_and (grays , grays , mask = mask )
296
+ cv2 .namedWindow ("Segmentation" ,cv2 .WINDOW_AUTOSIZE )
297
+ cv2 .imshow ("Segmentation" , mask )
298
+ elif k == 93 :
275
299
grays = cv2 .cvtColor (backdrop , cv2 .COLOR_BGR2GRAY )
276
- for i in range (3 ,4 ):
277
- tooth_variations = all_landmarks_std [:,i ]
278
- # print(tooth_variations)
279
- # print(output[:,0])
280
- tooth_points = np .empty ((40 ,2 ))
300
+ mask = np .zeros (grays .shape , np .uint8 )
301
+ test = output [0 ,0 ,:,:].astype (np .int32 )
302
+ cv2 .fillConvexPoly (mask , test ,(255 ,255 ,255 ))
303
+ segmentation = cv2 .bitwise_and (grays , grays , mask = mask )
304
+ mask = cv2 .resize (mask , (int (size [0 ]/ 2 ),int (size [1 ]/ 2 )))
305
+ retval , mask = cv2 .threshold (mask , 5 , 255 , cv2 .THRESH_BINARY )
306
+ cv2 .namedWindow ("Segmentation" ,cv2 .WINDOW_AUTOSIZE )
307
+ cv2 .imshow ("Segmentation" , mask )
308
+ dir_segmentations = "_Data\\ Segmentations\\ %02d-0.png" % currentImage
309
+
310
+ segCompare = cv2 .imread (dir_segmentations , 0 )
311
+ segCompare = cv2 .resize (segCompare , (int (size [0 ]/ 2 ),int (size [1 ]/ 2 )))
312
+ retval , segCompare = cv2 .threshold (segCompare , 5 , 255 , cv2 .THRESH_BINARY )
313
+ cv2 .namedWindow ("ExampleSeg" ,cv2 .WINDOW_AUTOSIZE )
314
+ cv2 .imshow ("ExampleSeg" , segCompare )
315
+
316
+ err1 = segCompare - mask
317
+ err2 = mask - segCompare
318
+ err = cv2 .bitwise_or (err1 , err2 )
319
+ totalpix = cv2 .bitwise_or (mask ,segCompare )
320
+ # retval, err = cv2.threshold(err, 5, 255, cv2.THRESH_BINARY)
321
+ # print(np.sum(err)/np.count_nonzero(err))
322
+ # print(np.count_nonzero(segCompare))
323
+ # print(np.count_nonzero(err))
324
+
325
+ # err = np.equal(segCompare,mask).astype(np.uint8)
326
+ retval , err = cv2 .threshold (err , 1 , 255 , cv2 .THRESH_BINARY )
327
+ print ("The segmentation is %0.2f %% correct" % ((1 - (np .count_nonzero (err )/ np .count_nonzero (totalpix )))* 100 ))
328
+ cv2 .namedWindow ("diff" ,cv2 .WINDOW_AUTOSIZE )
329
+ cv2 .imshow ("diff" , err )
330
+
331
+ elif k == 105 :
332
+ tempShow ("Calculating Edges + PCA..." )
333
+ grays = cv2 .cvtColor (backdrop , cv2 .COLOR_BGR2GRAY )
334
+ edge_img , pca_teeth = asm .preperation_all (grays , all_landmarks_std )
335
+ tempShow ("Calculating Edges + PCA : DONE!" )
336
+ elif k == 111 :
337
+ for i in range (0 ,8 ):
281
338
tooth_points = output [0 ,i ,:,:]
282
- edge_img , pca_tooth = asm .preperation (grays , tooth_variations )
283
- points = asm .active_shape (edge_img , tooth_points , pca_tooth , 5 ,20 )
339
+ points = asm .active_shape (edge_img , tooth_points , pca_teeth [i ], 5 ,5 )
284
340
# print(all_landmarks_std[0,0,:,:])
285
341
output [0 ,i ,:,:] = points
286
- # print(output)
287
342
drawTeethOutput (output , backdrop )
288
- print ("done" )
343
+ # print(output)
344
+ tempShow ("ASM iteration complete!" )
289
345
elif k == 47 :
290
346
# print(output)
291
347
np .save ("initial_position" , output )
0 commit comments