2011-08-29 45 views
3

您碰巧有用Python编写的1D非最大抑制算法吗?我需要它使用scipy在Python中制作一个Canny边缘检测器,该检测器需要输入一维强度矢量。Python/scipy中的1D非最大抑制

我在网上浏览过很多信息,描述了Canny边缘检测器的行为以及用Java编写的一些示例,但它们都描述了2D中的边缘检测。

然而,scipy确实支持Canny边缘检测所需的其他算法,即1D的高斯滤波和微分。

在此先感谢。

回答

2

你只是指最大的过滤器?如果是这样,必须在scipy.ndimage.maximum_filter1d

看看作为一个简单的例子:

import numpy as np 
import scipy.ndimage as ndimage 

input = np.sin(np.linspace(0, 4*np.pi, 20)) 
input = (input * 10).astype(np.int) # Makes it easier to read 
output = ndimage.maximum_filter1d(input, 4) 

print 'In: ', input 
print 'Out:', output 

这产生了:

In: [ 0 6 9 9 4 -1 -7 -9 -8 -3 3 8 9 7 1 -4 -9 -9 -6 0] 
Out: [ 6 9 9 9 9 9 4 -1 -3 3 8 9 9 9 9 7 1 -4 0 0]