我有以下正在稳步增加的点列表,例如:
[[0, 0], [9, 4], [18, 19], [25, 34], [48, 48], [54, 53], [61, 65], [69, 82], [73, 86], [87, 99]]
但我碰巧遇到了一些违反这种模式的点,如下表所示:
[526, 590], [532, 599], [605, 539], [740, 519], [753, 539], [858, 700], [981, 615], [985, 539], [1105, 700], [1222, 590], [1359, 343], [1456, 86], [1617, 4], [1790, 44], [1885, 1927], [2016, 2008]
所以,我需要找到一种方法来修剪/过滤掉这些违反模式的点,在这种情况下,指向从[605, 539]
到[1790, 44]
我尝试使用以下内容,仅接受 y 坐标位于前一个点的 y 坐标和下一个点的 y 坐标之间的点:
for i, pt in enumerate(points[1:-1]):
x,y=cur_pt=points[i]
x0,y0=prev_pt=points[i-1]
x1,y1=next_pt=points[i+1]
if y<y1 and y>y0:
print 'acceptable point'
else:
print 'pruned'
问题是它修剪了许多有效点并留下了一些需要修剪的点。
点列表在这里:
points=[[0, 0], [9, 4], [18, 19], [25, 34], [48, 48], [54, 53], [61, 65], [69, 82], [73, 86], [87, 99], [93, 105], [96, 108], [98, 110], [99, 111], [100, 112], [106, 118], [119, 131], [128, 140], [134, 146], [137, 149], [139, 151], [140, 152], [141, 153], [147, 159], [160, 172], [185, 153], [213, 219], [215, 241], [219, 245], [223, 249], [236, 262], [247, 276], [249, 278], [274, 302], [282, 294], [288, 318], [313, 352], [365, 419], [377, 423], [416, 458], [435, 468], [468, 519], [481, 539], [508, 559], [526, 590], [532, 599], [605, 539], [740, 519], [753, 539], [858, 700], [981, 615], [985, 539], [1105, 700], [1222, 590], [1359, 343], [1456, 86], [1617, 4], [1790, 44], [1885, 1927], [2016, 2008], [2072, 2137], [2186, 2212], [2219, 2477], [2260, 2482], [2425, 2477], [2568, 2460], [2646, 2609], [2816, 2792], [2913, 2686], [2960, 2853], [3072, 2959], [3210, 2925], [3249, 2809], [3359, 2959], [3446, 3057], [3517, 2809], [3809, 2959], [4033, 3190], [4232, 3057], [4439, 2809], [4632, 3057], [4706, 2809], [4715, 1922], [4725, 1596], [5058, 1560], [5066, 1596], [5107, 1560], [5362, 1333], [5432, 1471], [5519, 1560], [5610, 1471], [5693, 249], [5782, 1471], [5968, 1560], [6068, 1471], [6105, 1560], [6298, 1700], [6390, 3765], [6416, 5926], [6446, 6440], [6503, 7300], [6511, 7332], [6522, 7342]]