数字图像处理与Python实现-图像降噪-巴特沃斯低通滤波

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wujuxKkoolerter/article/details/102733325

巴特沃斯低通滤波

n阶巴特沃斯低通滤波器,传递函数为:
$$
H(u,v) = \frac{1}{1 + (D(u,v) / D_0)^{2n}}

\tag{7-1}
$$

其中, D ( u , v ) = ( u P 2 ) 2 + ( v Q 2 ) 2 D(u,v) = \sqrt{(u - \frac{P}{2})^2 + (v - \frac{Q}{2})^2} , D 0 D_0 是截止频率,取正数,用来控制曲线的形状。当 D ( u , v ) = D 0 , n = 1 D(u,v)=D_0,n=1 时, H ( u , v ) H(u,v) D 0 D_0 处的值降为其最大值为 1 2 , H ( u , v ) \frac{1}{\sqrt{2}},H(u,v) 具有不同的衰减特性,可视情况来确定。

巴特沃斯低通滤波器传递函数特性为连续性衰减,而不像理想低通滤波器那样陡峭和明显的不连续性;尾部保留有较多的高频,所以对噪声的平滑效果不如理想滤波器。巴特沃斯滤波器在抑制噪声的同时,图像边缘的模糊程序大大减小,振铃效应不明显,但是随着阶次增加,振铃现象会越来明显。

在这里插入图片描述

Python实现如下:

def butterworth_low_pass_kernel(img,cut_off,butterworth_order=1):
    assert img.ndim == 2
    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 )
    denom = 1.0 + (low_pass / cut_off)**(2 * butterworth_order)
    low_pass = 1.0 / denom
    return low_pass

def butterworth_low_pass(src,D0=5,butterworth_order=1):
    assert src.ndim == 2
    kernel = butterworth_low_pass_kernel(src,D0,butterworth_order)
    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)

程序运行结果如下:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/wujuxKkoolerter/article/details/102733325