指数型高通滤波
指数型高通滤波器的传递函数如下:
H(u,v)=1−exp(ln(1/2)(D(u,v)/D0)n)
Python语言实现如下:
def index_low_pass_kernel(img,D0,n=1):
r,c = img.shape[1],img.shape[0]
u = np.arange(r)
v = np.arange(c)
u, v = np.meshgrid(u, v)
low_pass = np.sqrt( (u-r/2)**2 + (v-c/2)**2 )
low_pass = np.exp(np.log(1 / np.sqrt(2)) * ((low_pass / D0)**n))
# low_pass = np.clip(low_pass,0,1)
return low_pass
def index_high_pass_filter(src,D0=5,n=1):
assert src.ndim == 2
kernel = 1 - index_low_pass_kernel(src,D0,n)
gray = np.float64(src)
gray_fft = np.fft.fft2(gray)
gray_fftshift = np.fft.fftshift(gray_fft)
dst = np.zeros_like(gray_fftshift)
dst_filtered = kernel * gray_fftshift
dst_ifftshift = np.fft.ifftshift(dst_filtered)
dst_ifft = np.fft.ifft2(dst_ifftshift)
dst = np.abs(np.real(dst_ifft))
dst = np.clip(dst,0,255)
return np.uint8(dst)
程序实现代码如下: