[英]Lowpass then Inverse Filter in Python
Trying to write a simple lowpass filter in python to run against lena. 尝试在python中编写一个简单的低通滤波器以针对lena运行。 Then I'd like to run an inverse filter to run against the lowpass and try to get the original back (well, as close to original).
然后,我想运行一个逆滤波器,以针对低通运行,并尝试将原始图像取回(好吧,尽可能接近原始图像)。 I'm new to programming in python and not quite sure where to start.
我是python编程的新手,不太确定从哪里开始。 I tried rearranging a highpass filter code but it doesn't look right.
我尝试重新排列高通滤波器代码,但看起来不正确。
import matplotlib.pyplot as plt
import numpy as np
import scipy.misc
from scipy import ndimage
import Image
#lowpass
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...
img = scipy.misc.lena()
data = np.array(img, dtype=float)
plot(data, 'Original')
#narrow lowpass filter
kernel = np.array([[1, 1, 1],
[1, -8, 1],
[1, 1, 1]])
lp_3 = ndimage.convolve(data, kernel)
plot(lp_3, '3x3 Lowpass')
# A slightly "wider" lowpass 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]])
lp_5 = ndimage.convolve(data, kernel)
plot(lp_5, '5x5 Lowpass')
plt.show()
You should definitely check your kernel first. 您绝对应该先检查内核。 It does not look like a lowpass (averaging) kernel at all.
它看起来根本不像低通(平均)内核。 Try first something like
首先尝试类似
kernel = np.ones((n,n))
if you want to do a very simple lowpass filter n by n (ie blurring): 如果您想做一个非常简单的低通滤镜n×n(即模糊):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.