2011-05-23 163 views

回答

34

「高通濾波器」是一個非常通用的術語。有許多不同的「高通濾波器」可以完成不同的事情(例如,如前所述,邊緣檢測濾波器在技術上是高通濾波器(大多數實際上是帶通濾波器),但與您可能產生的效果截然不同)

無論如何,基於大多數問題,你應該看看scipy.ndimage而不是scipy.filter,尤其是如果你打算使用大圖像(ndimage can瓶坯操作就地,節約內存)。

作爲一個基本的例子,顯示了做事情的幾種不同的方式:

import matplotlib.pyplot as plt 
import numpy as np 
from scipy import ndimage 
import Image 

def plot(data, title): 
    plot.i += 1 
    plt.subplot(2,2,plot.i) 
    plt.imshow(data) 
    plt.gray() 
    plt.title(title) 
plot.i = 0 

# Load the data... 
im = Image.open('lena.png') 
data = np.array(im, dtype=float) 
plot(data, 'Original') 

# A very simple and very narrow highpass filter 
kernel = np.array([[-1, -1, -1], 
        [-1, 8, -1], 
        [-1, -1, -1]]) 
highpass_3x3 = ndimage.convolve(data, kernel) 
plot(highpass_3x3, 'Simple 3x3 Highpass') 

# A slightly "wider", but sill very simple highpass filter 
kernel = np.array([[-1, -1, -1, -1, -1], 
        [-1, 1, 2, 1, -1], 
        [-1, 2, 4, 2, -1], 
        [-1, 1, 2, 1, -1], 
        [-1, -1, -1, -1, -1]]) 
highpass_5x5 = ndimage.convolve(data, kernel) 
plot(highpass_5x5, 'Simple 5x5 Highpass') 

# Another way of making a highpass filter is to simply subtract a lowpass 
# filtered image from the original. Here, we'll use a simple gaussian filter 
# to "blur" (i.e. a lowpass filter) the original. 
lowpass = ndimage.gaussian_filter(data, 3) 
gauss_highpass = data - lowpass 
plot(gauss_highpass, r'Gaussian Highpass, $\sigma = 3 pixels$') 

plt.show() 

enter image description here

+0

感謝一個偉大的劇本!我學到了很多關於convolve()和matplotlib *和*甚至Python的知識。 (我不知道像「plot.i」這樣的東西可以工作。) – 2011-07-28 13:00:54

+0

是不是高斯濾波器的低通濾波器? – 2013-11-10 14:44:50

+0

@ A.H。 - 是的,但是如果從原始圖像中減去高斯低通,您將得到一個等效的高通濾波器。這就是所謂的「高斯高通」。 (看看上面代碼的註釋部分。) – 2013-11-10 16:21:43

1

scipy.filter含有大量的通用過濾器。類似iirfilter類可以配置爲產生典型的Chebyshev或Buttworth數字或模擬高通濾波器。

4

一個簡單的高通濾波器是:

-1 -1 -1 
-1 8 -1 
-1 -1 -1 

Sobel operator的是另一種簡單的例子。

在圖像處理中,這些過濾器通常被稱爲「邊緣檢測器」 - the Wikipedia page在我上次檢查時確定。