2024-09-30 08:25:51 发布
网友
我有一个点数组,[(x,y),…],收集自用户鼠标线条绘制,我想用移动平均法去除其中的噪声
我该怎么做
看 https://docs.scipy.org/doc/scipy/reference/signal.html#filtering
或者只要使用convolve并在必要时更正边框即可
如果可以在项目中使用opencv,请参见 https://docs.opencv.org/4.5.2/d4/d86/group__imgproc__filter.html 和使用
a = np.array(list_of_points, 'f') # should be floating kernel_size = 3 # for example filtered = cv2.blur(a, (1, kernel_size), borderType=cv2.BORDER_REPLICATE)
下面是使用大小为s的卷积的示例:
s
v = np.array([(0, 4), (1, 5), (2, 6), (-1, 9), (3, 7), (4, 8), (5, 9)]) s = 2 kernel = np.ones(s) x = np.convolve(v[:,0], kernel, 'valid') / s y = np.convolve(v[:,1], kernel, 'valid') / s res = np.hstack((x[:, None], y[:, None])) print(res)
输出:
[[0.5 4.5] [1.5 5.5] [0.5 7.5] [1. 8. ] [3.5 7.5] [4.5 8.5]]
越大的s,路径越平滑。但是s越大,路径越短
看 https://docs.scipy.org/doc/scipy/reference/signal.html#filtering
或者只要使用convolve并在必要时更正边框即可
如果可以在项目中使用opencv,请参见 https://docs.opencv.org/4.5.2/d4/d86/group__imgproc__filter.html 和使用
下面是使用大小为
s
的卷积的示例:输出:
越大的
s
,路径越平滑。但是s
越大,路径越短相关问题 更多 >
编程相关推荐