为什么在我的情况下,韦纳滤波器只能降低噪声,而不能降低模糊量 [英] why weiner filter reduces only noise in my case, it is not reducing blur amount

查看:38
本文介绍了为什么在我的情况下,韦纳滤波器只能降低噪声,而不能降低模糊量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python实现weiner滤波,该滤波将应用于使用磁盘形状点扩散函数模糊的图像,其中包括制作磁盘形状psf和weiner滤波器的代码

 def weinerFiltering(内核,K_const,图像):#F(u,v)copy_img = np.copy(image)image_fft = np.fft.fft2(copy_img)#H(u,v)kernel_fft = np.fft.fft2(内核,s = copy_img.shape)#H_mag(u,v)kernel_fft_mag = np.abs(内核_fft)#H *(u,v)kernel_conj = np.conj(内核_fft)f =(内核conj)/(内核fft_mag ** 2 + K_const)返回np.abs(np.fft.ifft2(image_fft * f))def makeDiskShape(arr,radius,centrX,centrY):对于范围内的我(centrX-radius,centrX + radius):对于范围内的j(centrY-radius,centrY + radius):if(l2dist(centrX,centrY,i,j)<=半径):arr [i] [j] = 1返回arr/np.sum(arr) 

对上面的图像进行反卷积得到的 out 图像如下所示:

不要期望完美的结果.正则化项妨碍了完美的逆滤波,因为这种滤波会极大地增强噪声,以至于会淹没信号并产生完全无用的输出.维纳滤波器在消除卷积和抑制噪声之间找到了中间立场.

用于 WienerDeconvolution 的DIPlib文档>解释其中涉及的一些方程式.

I am implementing weiner filtering in python which is applied on an image blurred using disk shape point spread function, i am including code of making disk shape psf and weiner filter


def weinerFiltering(kernel,K_const,image):
    #F(u,v)
    copy_img= np.copy(image)
    image_fft =np.fft.fft2(copy_img)
    #H(u,v)
    kernel_fft  = np.fft.fft2(kernel,s=copy_img.shape)
    #H_mag(u,v)
    kernel_fft_mag = np.abs(kernel_fft)
    #H*(u,v)
    kernel_conj = np.conj(kernel_fft)

    f = (kernel_conj)/(kernel_fft_mag**2 + K_const)
    return np.abs(np.fft.ifft2(image_fft*f))


def makeDiskShape(arr,radius,centrX,centrY):
    for i in range(centrX-radius,centrX+radius):
        for j in range(centrY-radius,centrY+radius):
            if(l2dist(centrX,centrY,i,j)<=radius):
                arr[i][j]=1
    return arr/np.sum(arr)


this is blurred and gaussian noised image

this is what i am getting result after weiner filtering for K value of 50 result does not seem very good, can someone help seems noise is reduced but amount of blurred is not, shape of disk shaped psf matrix is 20,20 and radius is 9 which seems like this

Update using power spectrum of ground truth image and noise to calculate K constant value, still i am getting strong artifacts this is noised and blurred image

this is result after using power specturm in place of a constant K value

解决方案

Reduce your value of K. You need to play around with it until you get good results. If it's too large it doesn't filter, if it's too small you get strong artifacts.

If you have knowledge of the noise variance, you can use that to estimate the regularization parameter. In the Wiener filter, the constant K is a simplification of N/S, where N is the noise power and S is the signal power. Both these values are frequency-dependent. The signal power S can be estimated by the Fourier transform of the autocorrelation function of the image to be filtered. The noise power is hard to estimate, but if you have such an estimate (or know it because you created the noisy image synthetically), then you can plug that value into the equation. Note that this is the noise power, not the variance of the noise.

The following code uses DIPlib (the Python interface we call PyDIP) to demonstrate Wiener deconvolution (disclaimer: I'm an author). I don't think it is hard to convert this code to use other libraries.

import PyDIP as dip

image = dip.ImageRead('trui.ics');
kernel = dip.CreateGauss([3,3]).Pad(image.Sizes())

smooth = dip.ConvolveFT(image, kernel)
smooth = dip.GaussianNoise(smooth, 5.0)  # variance = 5.0

H = dip.FourierTransform(kernel)
F = dip.FourierTransform(smooth)
S = dip.SquareModulus(F)  # signal power estimate
N = dip.Image(5.0 * smooth.NumberOfPixels())  # noise power (has same value at all frequencies)

Hinv = dip.Conjugate(H) / ( dip.SquareModulus(H) + N / S )

out = dip.FourierTransform(F * Hinv, {"inverse", "real"})

The smooth image looks like this:

The out image that comes from deconvolving the image above looks like this:

Don't expect a perfect result. The regularization term impedes a perfect inverse filtering because such filtering would enhance the noise so strongly that it would swamp the signal and produce a totally useless output. The Wiener filter finds a middle ground between undoing the convolution and suppressing the noise.

The DIPlib documentation for WienerDeconvolution explains some of the equations involved.

这篇关于为什么在我的情况下,韦纳滤波器只能降低噪声,而不能降低模糊量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆