数字图像处理与Python实现-图像降噪-高斯带阻带通滤波

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

高斯带阻带通滤波

高斯带阻滤波传递函数如下:

H ( u , v ) = 1 e 1 2 [ D 2 ( u , v ) D 0 2 D ( u , v ) W ] 2 H(u,v) = 1 - e^{-\frac{1}{2}[\frac{D^2(u,v) - D_0^2}{D(u,v)W}]^2}

高斯带通滤波传递函数如下:

H ( u , v ) = e 1 2 [ D 2 ( u , v ) D 0 2 D ( u , v ) W ] 2 H(u,v) = e^{-\frac{1}{2}[\frac{D^2(u,v) - D_0^2}{D(u,v)W}]^2}

Python实现如下:

def gaussian_bandstop_kernel(img,D0,W):
    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 )

    kernel = 1.0 - np.exp(-0.5 * (((low_pass ** 2 - D0**2) / (low_pass *W + 1.0e-5))**2))
    return kernel

def gaussian_bandstop_filter(img,D0=5,W=10):
    assert img.ndim == 2
    kernel = gaussian_bandstop_kernel(img,D0,W)
    gray = np.float64(img)
    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)

def gaussian_bandpass_filter(img,D0=5,W=10):
    assert img.ndim == 2
    kernel = 1.0 - gaussian_bandstop_kernel(img,D0,W)
    gray = np.float64(img)
    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/102759047