-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothing.py
95 lines (69 loc) · 2.49 KB
/
smoothing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import SimpleITK as sitk
import time
PATH = 'tooth/005.nii.gz'
SAVE_PATH = 'tooth/post_005.nii.gz'
#template
def smoothing(path, save_path):
sitkImage = sitk.ReadImage(path)
#write smoothing method here
sitkImage = sitkFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
pass
def dilation(path, save_path):
sitkImage = sitk.ReadImage(path)
#write smoothing method here
dilateFilter = sitk.BinaryDilateImageFilter()
dilateFilter.SetBackgroundValue(0)
for i in range(5):
dilateFilter.SetForegroundValue(i+1)
dilateFilter.SetKernelRadius(3)
print(str(i+1) + '...')
sitkImage = dilateFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
def erosion(path, save_path):
sitkImage = sitk.ReadImage(path)
#write smoothing method here
erodeFilter = sitk.BinaryErodeImageFilter()
erodeFilter.SetBackgroundValue(0)
for i in range(3):
erodeFilter.SetForegroundValue(i+1)
erodeFilter.SetKernelRadius(3)
print(str(i+1) + '...')
sitkImage = erodeFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
def closing(path, save_path):
sitkImage = sitk.ReadImage(path)
closeFilter = sitk.BinaryMorphologicalClosingImageFilter()
for i in range(3):
closeFilter.SetForegroundValue(i+1)
closeFilter.SetKernelRadius(3)
print(str(i+1) + '...')
sitkImage = closeFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
def median(path, save_path):
sitkImage = sitk.ReadImage(path)
medianFilter = sitk.MedianImageFilter()
medianFilter.SetRadius(2)
sitkImage = medianFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
def post(path, save_path):
sitkImage = sitk.ReadImage(path)
medianFilter = sitk.MedianImageFilter()
medianFilter.SetRadius(2)
sitkImage = medianFilter.Execute(sitkImage)
dilateFilter = sitk.BinaryDilateImageFilter()
dilateFilter.SetBackgroundValue(0)
for i in range(32):
dilateFilter.SetForegroundValue(i+1)
dilateFilter.SetKernelRadius(1)
print(str(i+1) + '...')
sitkImage = dilateFilter.Execute(sitkImage)
sitk.WriteImage(sitkImage, save_path)
if __name__=="__main__":
_time = time.time()
#closing(PATH, SAVE_PATH)
#dilation(PATH, SAVE_PATH)
#erosion(PATH, SAVE_PATH)
#median(PATH, SAVE_PATH)
post(PATH, SAVE_PATH)
print('\nTime spent: ' + str(time.time() - _time) + 's')