我试图在python中为一个赋值实现notch-reject过滤。我尝试使用Rafael Gonzales书中的陷波抑制滤波器公式,得到的只是一张边缘检测图像。然后我尝试了理想切口,结果如下:
Input image--Output of my program--Expected output
这是我的密码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
def notch_reject_filter(shape, d0=9, u_k=0, v_k=0):
P, Q = shape
# Initialize filter with zeros
H = np.zeros((P, Q))
# Traverse through filter
for u in range(0, P):
for v in range(0, Q):
# Get euclidean distance from point D(u,v) to the center
D_uv = np.sqrt((u - P / 2 + u_k) ** 2 + (v - Q / 2 + v_k) ** 2)
D_muv = np.sqrt((u - P / 2 - u_k) ** 2 + (v - Q / 2 - v_k) ** 2)
if D_uv <= d0 or D_muv <= d0:
H[u, v] = 0.0
else:
H[u, v] = 1.0
return H
img = cv2.imread('input.png', 0)
img_shape = img.shape
original = np.fft.fft2(img)
center = np.fft.fftshift(original)
NotchRejectCenter = center * notch_reject_filter(img_shape, 32, 50, 50)
NotchReject = np.fft.ifftshift(NotchRejectCenter)
inverse_NotchReject = np.fft.ifft2(NotchReject) # Compute the inverse DFT of the result
plot_image = np.concatenate((img, np.abs(inverse_NotchReject)),axis=1)
plt.imshow(plot_image, "gray"), plt.title("Notch Reject Filter")
plt.show()
我得到的是一个边缘检测图像,因为您的实现是强>高通<强>过滤器,中间是一个黑圆圈,作为边缘检测器。<李>- 然后我尝试了如果你应用正确,这是正确的李>
主要概念是在频域中过滤不需要的噪声,噪声可以被视为白点,您的角色是通过在频域中将白点乘以黑圈来抑制这些白点(称为过滤)
相关问题 更多 >
编程相关推荐