-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothen_surface.py
47 lines (41 loc) · 1.85 KB
/
smoothen_surface.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
#
# .. _smoothen_surface:
#
# Function for smoothing the voxel surface generated by MRI scans
# ================================================================
# Copyright (C) 2023 Adeeb Arif Kor
def smoothen(surface, num_iteration):
smooth_surface = surface.copy()
num_points_1 = smooth_surface.shape[0]
num_points_2 = smooth_surface.shape[1]
smooth_surface_boundary_1 = smooth_surface[0, :]
smooth_surface_boundary_2 = smooth_surface[-1, :]
smooth_surface_boundary_3 = smooth_surface[:, 0]
smooth_surface_boundary_4 = smooth_surface[:, -1]
for _ in range(num_iteration):
for i in range(1, num_points_1-1):
for j in range(1, num_points_2-1):
smooth_surface[i, j] = (
smooth_surface[i-1, j-1] + smooth_surface[i, j-1] +
smooth_surface[i+1, j-1] + smooth_surface[i-1, j] +
smooth_surface[i, j] + smooth_surface[i+1, j] +
smooth_surface[i-1, j+1] + smooth_surface[i, j+1] +
smooth_surface[i+1, j+1]) / 9.0
for _ in range(num_iteration):
smooth_surface_boundary_1[1:-1:] = (
smooth_surface_boundary_1[:-2:] +
smooth_surface_boundary_1[1:-1:] +
smooth_surface_boundary_1[2::]) / 3.0
smooth_surface_boundary_2[1:-1:] = (
smooth_surface_boundary_2[:-2:] +
smooth_surface_boundary_2[1:-1:] +
smooth_surface_boundary_2[2::]) / 3.0
smooth_surface_boundary_3[1:-1:] = (
smooth_surface_boundary_3[:-2:] +
smooth_surface_boundary_3[1:-1:] +
smooth_surface_boundary_3[2::]) / 3.0
smooth_surface_boundary_4[1:-1:] = (
smooth_surface_boundary_4[:-2:] +
smooth_surface_boundary_4[1:-1:] +
smooth_surface_boundary_4[2::]) / 3.0
return smooth_surface