感觉和测度空间有关系,暂时记下。
An包含于An-1...包含于A1.An是最终的细化骨架。
def zhangSuen(image):
"the Zhang-Suen Thinning Algorithm"
Image_Thinned = image.copy() # deepcopy to protect the original image
changing1 = changing2 = 1 # the points to be removed (set as 0)
while changing1 or changing2: # iterates until no further changes occur in the image
# Step 1
changing1 = []
rows, columns = Image_Thinned.shape # x for rows, y for columns
for x in range(1, rows - 1): # No. of rows
for y in range(1, columns - 1): # No. of columns
P2,P3,P4,P5,P6,P7,P8,P9 = n = neighbours(x, y, Image_Thinned)
if (Image_Thinned[x][y] == 1 and # Condition 0: Point P1 in the object regions
2 <= sum(n) <= 6 and # Condition 1: 2<= N(P1) <= 6
transitions(n) == 1 and # Condition 2: S(P1)=1
P2 * P4 * P6 == 0 and # Condition 3
P4 * P6 * P8 == 0): # Condition 4
changing1.append((x,y))
for x, y in changing1:
Image_Thinned[x][y] = 0
# Step 2
changing2 = []
for x in range(1, rows - 1):
for y in range(1, columns - 1):
P2,P3,P4,P5,P6,P7,P8,P9 = n = neighbours(x, y, Image_Thinned)
if (Image_Thinned[x][y] == 1 and # Condition 0
2 <= sum(n) <= 6 and # Condition 1
transitions(n) == 1 and # Condition 2
P2 * P4 * P8 == 0 and # Condition 3
P2 * P6 * P8 == 0): # Condition 4
changing2.append((x,y))
for x, y in changing2:
Image_Thinned[x][y] = 0
return Image_Thinned