2011-08-29 58 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]