高通滤波器使用scipy / numpy在python中进行图像处理 [英] High Pass Filter for image processing in python by using scipy/numpy
问题描述
我目前正在研究图像处理。在Scipy中,我知道Scipy.signal中有一个中值过滤器。任何人都可以告诉我是否有一个类似于高通滤波器的滤波器?
I am currently studying image processing. In Scipy, I know there is one median filter in Scipy.signal. Can anyone tell me if there is one filter similar to high pass filter?
谢谢
推荐答案
高通滤波器是一个非常通用的术语。有无数种不同的高通滤波器做了很多不同的事情(例如,如前所述,边缘检测滤波器在技术上是高通(大多数实际上是带通)滤波器,但与你可能的效果有很大不同请记住。)
"High pass filter" is a very generic term. There are an infinite number of different "highpass filters" that do very different things (e.g. an edge dectection filter, as mentioned earlier, is technically a highpass (most are actually a bandpass) filter, but has a very different effect from what you probably had in mind.)
无论如何,根据您提出的大多数问题,您应该查看 scipy.ndimage
而不是 scipy.filter
,特别是如果您要使用大图像(ndimage可以就地执行操作,节省内存)。
At any rate, based on most of the questions you've been asking, you should probably look into scipy.ndimage
instead of scipy.filter
, especially if you're going to be working with large images (ndimage can preform operations in-place, conserving memory).
作为一个基本的例子,展示一些不同的做事方式:
As a basic example, showing a few different ways of doing things:
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()
这篇关于高通滤波器使用scipy / numpy在python中进行图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!