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 9fa4c84

Browse files
code cleanup
1 parent cda741d commit 9fa4c84

File tree

6 files changed

+135
-788
lines changed

6 files changed

+135
-788
lines changed

‎.ipynb_checkpoints/ActiveContour-checkpoint.ipynb

Lines changed: 26 additions & 149 deletions
Large diffs are not rendered by default.

‎.ipynb_checkpoints/FitFunction-checkpoint.ipynb

Lines changed: 18 additions & 128 deletions
Large diffs are not rendered by default.

‎ActiveContour.ipynb

Lines changed: 26 additions & 149 deletions
Large diffs are not rendered by default.

‎ActiveContour.py

Lines changed: 30 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11

22
# coding: utf-8
33

4-
# In[159]:
4+
# In[5]:
55

66

77
import numpy as np
88
import matplotlib.pyplot as plt
99
from skimage.color import rgb2gray
1010
from skimage.filters import gaussian
11-
import ActiveShapeModel
1211
import scipy
1312
import cv2
1413
from scipy import ndimage
1514
import Image_preperation as prep
1615
import FileManager as fm
17-
import Image_preperation as prep
1816

1917
def calc_internal(p1,p2):
2018
if (np.array_equal(p1,p2)):
@@ -41,19 +39,19 @@ def calc_mean(points):
4139

4240
return mean_sum / size
4341

44-
def calc_external_img(img):
42+
# def calc_external_img(img):
4543

46-
img = rgb2gray(img)
44+
# img = rgb2gray(img)
4745

48-
sobelx64f = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
49-
abs_sobel64f = np.absolute(sobelx64f)
50-
sobelx = np.uint8(abs_sobel64f)
46+
# sobelx64f = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
47+
# abs_sobel64f = np.absolute(sobelx64f)
48+
# sobelx = np.uint8(abs_sobel64f)
5149

52-
sobely64f = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)
53-
abs_sobel64f = np.absolute(sobely64f)
54-
sobely = np.uint8(abs_sobel64f)
50+
# sobely64f = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)
51+
# abs_sobel64f = np.absolute(sobely64f)
52+
# sobely = np.uint8(abs_sobel64f)
5553

56-
return -(sobelx + sobely)
54+
# return -(sobelx + sobely)
5755

5856
def calc_external_img2(img):
5957

@@ -101,7 +99,7 @@ def calc_energy3(p1, p2, mean, external_img, alpha):
10199
internal = calc_internal_mean(p1,p2, mean)
102100
external = calc_external(p2, external_img)
103101

104-
return alpha*internal + external
102+
return internal +alpha* external
105103

106104

107105

@@ -154,8 +152,8 @@ def viterbi(points, img, pixel_width, alpha):
154152
for d in range(num_states):
155153
p1 = get_point_state(points[i-1], d, pixel_width)
156154
p2 = get_point_state(points[i],t, pixel_width)
157-
#energy_trans = calc_energy(p1, p2, external_img, alpha)
158-
energy_trans = calc_energy3(p1, p2, mean, external_img, alpha)
155+
energy_trans = calc_energy(p1, p2, external_img, alpha)
156+
# energy_trans = calc_energy3(p1, p2, mean, external_img, alpha)
159157

160158
tmp = trellis[i-1,d] + energy_trans
161159

@@ -251,12 +249,7 @@ def resolution_downscale(img, resize):
251249

252250
return cv2.resize(img, (yn ,xn))
253251

254-
255-
# In[169]:
256-
257-
258-
if __name__ == "__main__":
259-
252+
def previous_test():
260253
dir_radiographs = "_Data\Radiographs\*.tif"
261254
radiographs = fm.load_files(dir_radiographs)
262255
radiograph = radiographs[0]
@@ -266,175 +259,32 @@ def resolution_downscale(img, resize):
266259
tooth = init[0,4,:,:]/0.3
267260
#tooth = tooth/down_sample
268261

269-
radiograph_pre = prep.pre_processing(radiograph)
262+
radiograph_pre = pre_processing(radiograph)
270263
img = resolution_downscale(radiograph_pre,down_sample)
271264

272265
fig, ax = plt.subplots(figsize=(15, 15))
273266
plt.imshow(radiograph)
274267
plt.plot(tooth[:,0], tooth[:,1], 'ro', markersize=1)
275268
plt.show()
276269

270+
def test_module():
271+
piece = fm.load_img_piece()
272+
tooth = fm.load_tooth_of_piece(0)
273+
ext = calc_external_img2(piece)
274+
fm.show_with_points(ext, tooth)
275+
276+
img, stooth = fm.resolution_scale(piece, tooth, 1/6)
277+
ext = calc_external_img2(img)
278+
fm.show_with_points(ext, stooth)
279+
280+
new_tooth = active_contour(stooth, img, 1, 3, 1)
281+
fm.show_with_points(ext, new_tooth)
277282

278-
# In[196]:
279-
280-
281-
smooth = prep.gaussian_smooth1(radiograph,10)
282-
grad = calc_external_img2(smooth)
283-
grad2 = calc_external_img2(radiograph)
284-
fig, ax = plt.subplots(figsize=(15, 15))
285-
plt.imshow(grad2)
286-
plt.show()
287-
print(radiograph.dtype)
288-
np.histogram(grad)
289-
fig, ax = plt.subplots(figsize=(15, 15))
290-
plt.imshow(grad)
291-
plt.show()
292-
293-
294-
# In[185]:
295-
296-
297-
img = radiograph
298-
299-
img = rgb2gray(img)
300-
301-
sobelx64f = cv2.Sobel(img,cv2.CV_16S,1,0,ksize=5)
302-
abs_sobel64f = np.absolute(sobelx64f)
303-
sobelx = np.uint8(abs_sobel64f)
304-
plt.imshow(sobelx)
305-
plt.show()
306-
307-
sobely64f = cv2.Sobel(img,cv2.CV_16S,0,1,ksize=5)
308-
abs_sobel64f = np.absolute(sobely64f)
309-
sobely = np.uint8(abs_sobel64f)
310-
plt.imshow(sobely64f)
311-
plt.show()
312-
313-
314-
# In[161]:
315-
316-
317-
k1 = np.array([[1,1,1],[1,1,1],[1,1,1]])/9
318-
smoothed = cv2.filter2D(img,-1,k1)
319-
320-
k2 = np.array([[0,0,0],[0,2,0],[0,0,0]])
321-
dubbel = cv2.filter2D(img,-1,k2)
322-
sharp = dubbel - smoothed
323-
sharp2 = 2*img - smoothed
324-
325-
plt.imshow(sharp)
326-
plt.show()
327-
plt.imshow(sharp2)
328-
plt.show()
329-
print(sharp2.dtype)
330-
331-
332-
# In[103]:
333-
334-
335-
piece = img[175:275, 225:325]
336-
tooth2 = tooth
337-
tooth2[:,0]=tooth[:,0]-225
338-
tooth2[:,1]=tooth[:,1]-175
339-
fig, ax = plt.subplots(figsize=(7, 7))
340-
plt.imshow(piece)
341-
plt.plot(tooth2[:,0], tooth2[:,1], 'ro', markersize=2)
342-
plt.show()
343-
344-
345-
# In[141]:
346-
347-
348-
new_tooth = active_contour(tooth2, prep.gaussian(piece,1.5), 2, 2, 25)
349-
fig, ax = plt.subplots(figsize=(7, 7))
350-
plt.imshow(piece)
351-
plt.plot(new_tooth[:,0], new_tooth[:,1], 'ro', markersize=2)
352-
plt.show()
353-
354-
355-
# In[137]:
356-
357-
358-
ext3 = calc_external_img2(piece)
359-
fig, ax = plt.subplots(figsize=(7, 7))
360-
plt.imshow(ext3)
361-
plt.plot(tooth2[0,0], new_tooth[0,1], 'ro', markersize=2)
362-
plt.show()
363-
364-
365-
# In[87]:
366-
367-
368-
tooth[:,0]=tooth[:,0]-225
369-
tooth[:,1]=tooth[:,1]-175
370-
371-
372-
# In[88]:
373-
374-
375-
for p in tooth:
376-
print(ext3[int(p[0]),int(p[1])])
377-
378-
379-
# In[127]:
380-
381-
382-
mean = calc_mean(tooth)
383-
size = len(tooth)
384-
for i in range(size-1):
385-
p1 = tooth[i]
386-
p2 = tooth[i+1]
387-
print(100*calc_internal_mean(p1,p2, mean))
388-
389-
390-
391-
# In[124]:
392-
393-
394-
mean
395-
396-
397-
# In[92]:
398-
399-
400-
size = len(tooth)
401-
for i in range(size-1):
402-
p1 = tooth[i]
403-
p2 = tooth[i+1]
404-
print(calc_energy(p1,p2,ext3,0.5))
405-
406-
407-
408-
# In[34]:
409-
410-
411-
ext.dtype
412-
413-
414-
# In[173]:
415-
416-
417-
new_tooth = active_contour(tooth, img, 5, 2, 1)
418-
419-
fig, ax = plt.subplots(figsize=(15, 15))
420-
plt.imshow(img)
421-
plt.plot(new_tooth[:,0], new_tooth[:,1], 'ro', markersize=1)
422-
plt.show()
423-
424-
425-
# In[143]:
426283

284+
# In[6]:
427285

428-
from skimage.color import rgb2gray
429-
from skimage import data
430-
from skimage.filters import gaussian
431-
from skimage.segmentation import active_contour
432286

433-
snake = active_contour(radiograph_pre,
434-
tooth, alpha=0.015, beta=10, gamma=0.001)
287+
if __name__ == "__main__":
435288

436-
fig, ax = plt.subplots(figsize=(15, 15))
437-
plt.imshow(img)
438-
plt.plot(snake[:,0], snake[:,1], 'ro', markersize=1)
439-
plt.show()
289+
test_module()
440290

‎FitFunction.ipynb

Lines changed: 18 additions & 128 deletions
Large diffs are not rendered by default.

‎FitFunction.py

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,23 @@ def test_normal_on_edge():
244244
plt.plot(np.arange(-20,21),strength)
245245
plt.show()
246246

247+
248+
def show_results_fitting():
249+
piece = fm.load_img_piece()
250+
edge_img = prep.canny(piece)
251+
tooth = fm.load_tooth_of_piece(0)
252+
new_points_list, total_error = fit_measure(tooth, 30, edge_img)
253+
for i in range(7):
254+
tooth = fm.load_tooth_of_piece(i+1)
255+
new_points, total_error = fit_measure(tooth, 25, edge_img)
256+
new_points_list = np.append(new_points_list,new_points)
257+
fm.show_with_points(edge_img, new_points_list.reshape(-1,2))
258+
259+
# new_points_list = fm.load_tooth_of_piece(0)
260+
# for i in range(7):
261+
# new_points = fm.load_tooth_of_piece(i+1)
262+
# new_points_list = np.append(new_points_list,new_points)
263+
# fm.show_with_points(edge_img, new_points_list.reshape(-1,2))
247264

248265

249266
# In[2]:
@@ -313,57 +330,3 @@ def test_normal_on_edge():
313330
# new_points, error = fit_measure(tooth, 30, edge_img)
314331
# fm.show_with_points(piece, new_points)
315332

316-
317-
# In[3]:
318-
319-
320-
piece = fm.load_img_piece()
321-
tooth = fm.load_tooth_of_piece(2)
322-
edge_img = prep.canny(piece)
323-
new_points, total_error = fit_measure(tooth, 20, edge_img)
324-
fm.show_with_points(edge_img, new_points)
325-
326-
327-
# In[4]:
328-
329-
330-
tooth = fm.load_tooth_of_piece(2)
331-
fm.show_with_points(edge_img, tooth)
332-
333-
334-
# In[3]:
335-
336-
337-
piece = fm.load_img_piece()
338-
edge_img = prep.canny(piece)
339-
tooth = fm.load_tooth_of_piece(0)
340-
new_points_list, total_error = fit_measure(tooth, 30, edge_img)
341-
for i in range(7):
342-
tooth = fm.load_tooth_of_piece(i+1)
343-
new_points, total_error = fit_measure(tooth, 25, edge_img)
344-
new_points_list = np.append(new_points_list,new_points)
345-
fm.show_with_points(edge_img, new_points_list.reshape(-1,2))
346-
347-
348-
# In[4]:
349-
350-
351-
new_points_list = new_points_list.reshape(-1,40,2)
352-
new_points_list.shape
353-
354-
355-
# In[19]:
356-
357-
358-
np.save('fitted_tooth', new_points_list)
359-
360-
361-
# In[12]:
362-
363-
364-
new_points_list = fm.load_tooth_of_piece(0)
365-
for i in range(7):
366-
new_points = fm.load_tooth_of_piece(i+1)
367-
new_points_list = np.append(new_points_list,new_points)
368-
fm.show_with_points(edge_img, new_points_list.reshape(-1,2))
369-

0 commit comments

Comments
(0)

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