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 3d18a82

Browse files
committed
small fix in FileManager.py
New teeth segmentation functionality in Initialisation.py We can now calculate how accurate our segmentations are in comparison to the given examples.
1 parent 0ef56fd commit 3d18a82

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

‎FileManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def load_tooth(i):
4141
init = np.load("initial_position.npy")
4242
return init[0,i,:,:]/0.3
4343

44-
def load_tooth_of_piece():
45-
tooth = load_tooth(4)
44+
def load_tooth_of_piece(num):
45+
tooth = load_tooth(num)
4646
tooth_of_piece = tooth
4747
tooth_of_piece[:,0]=tooth[:,0]-1200
4848
tooth_of_piece[:,1]=tooth[:,1]-700

‎Initialisation.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ def drawTeeth(landmarks,backdrop,tooth_size,image_center,tooth_gap,top_bottom_se
174174
cv2.circle(backdrop,(x,y),1,(255,255,255),-1)
175175
cv2.imshow("Radiograph",backdrop)
176176

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+
177187
def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
178188
dir_radiographs = directory
179189
radiographs = FileManager.load_files(dir_radiographs)
@@ -188,9 +198,14 @@ def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
188198
global size
189199
global scale
190200
global output
201+
global currentImage
191202
showpopup=1
192203
cv2.setMouseCallback('Radiograph',moveTeeth,(resized_image,all_landmarks_std))
193204

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!")
194209

195210

196211
loop=1
@@ -271,21 +286,62 @@ def InitializeASM(directory = "_Data\\Radiographs\\*.tif"):
271286
segmentation = cv2.bitwise_and(grays, grays, mask=mask)
272287
cv2.namedWindow("Segmentation",cv2.WINDOW_AUTOSIZE)
273288
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:
275299
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):
281338
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)
284340
# print(all_landmarks_std[0,0,:,:])
285341
output[0,i,:,:] = points
286-
# print(output)
287342
drawTeethOutput(output, backdrop)
288-
print("done")
343+
# print(output)
344+
tempShow("ASM iteration complete!")
289345
elif k == 47:
290346
# print(output)
291347
np.save("initial_position", output)

0 commit comments

Comments
(0)

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