通过相同大小的卷积,维纳滤镜无法处理模糊图像 [英] Wiener filter failed for blurry image by same size convolution

查看:65
本文介绍了通过相同大小的卷积,维纳滤镜无法处理模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MATLAB中测试Wiener滤波器以恢复模糊的图像.我正在使用conv2()来模糊原始图像.如果我对conv2()使用'full'选项,则一切正常.但是,当我更改为相同"或有效"时,突然在恢复的图像中出现了许多伪像,并且维纳滤镜失败了.请参阅下面的模糊图像,从完全"卷积恢复,从相同"卷积恢复.

I'm testing Wiener filter in MATLAB to restore a blurred image. I was using conv2() to blur the original image. If I use the 'full' option for conv2(), everything works well. But when I change to 'same' or 'valid', suddenly a lot of artifacts appeared in the restored image and Wiener filter failed. Please see below for blurred image, restoration from 'full' convolution, restoration from 'same' convolution.

这是我对维纳过滤器的实现:

Here's my implementation of the Wiener filter:

% load image
img = rgb2gray(imread('cameraman.jpg'));
[W, H] = size(img);
dim = 300;
img_fft = fft2(img,dim,dim);
% create blur kernel
kernel = ones(5) / 25;
kernel_fft = fft2(kernel,dim,dim);
% The option here makes huge difference 'same'/'full'/'valid'
img_blur = conv2(img,kernel,'same');
img_blur_fft = fft2(img_blur,dim,dim);
% Wiener filtering
k = 1e-5;
kernel_fft_conj = conj(kernel_fft);
img_wiener_freq = kernel_fft_conj .* img_blur_fft ./ (kernel_fft .* kernel_fft_conj + k);
img_wiener_ifft = ifft2(img_wiener_freq);
img_wiener_ifft = img_wiener_ifft(1:W,1:H);

在现实生活中,模糊的图像永远不会具有圆形或完全卷积的形式,我该如何正确实现维纳滤镜,使其不依赖于图像的边界?

As in real life the blurred image never has the form from circular or full convolution, how can I properly implement Wiener filter so it doesn't depends on the border of the image?

推荐答案

您为正则化参数 k 选择了一个非常小的值.在'full'的情况下,此方法可以很好地工作,因为没有噪音,并且输入与预期值完全匹配.但是,在'same'情况下,输入不完全匹配.如果要使用圆形卷积(例如,通过在傅立叶域中相乘),那么您还将获得准确的结果.

You have chosen a very small value for the regularization parameter k. This works fine in the 'full' case because there is no noise and the input exactly matches the expected. However, in the 'same' case the input does not exactly match. If you were to use a circular convolution (e.g. by multiplication in the Fourier domain) then you would also get an exact result.

存在正则化参数是为了防止小偏差膨胀并破坏整个输出图像.

The regularization parameter exists to prevent small deviations from blowing up and corrupting the whole output image.

使用 k = 1e-2 ( 1e-1 使图像模糊, 1e-3 仍然显示出很多结果),我得到了合理的结果整个图像中的伪像,但可以进一步微调此值,我没有为此付出更多的努力.)

I got reasonable results using k = 1e-2 (1e-1 leaves the image blurry, 1e-3 still shows a lot of artefacts throughout the image, but it is possible to further fine-tune this value, I have not put more effort in than that).

这是我使用的代码,有一些重要的区别:

This is the code I used, there are some important differences:

img = imread('cameraman.tif');
% create blur kernel
kernel = ones(5) / 25;
% The option here makes huge difference 'same'/'full'/'valid'
img_blur = conv2(img,kernel,'same');
img_blur_fft = fft2(img_blur);
% Wiener filtering
kernel_fft = padarray(kernel,size(img)-size(kernel),0,'post');
kernel_fft = circshift(kernel_fft,-floor(size(kernel)/2));
kernel_fft = fft2(kernel_fft);
k = 1e-2;
kernel_fft_conj = conj(kernel_fft);
img_wiener_freq = kernel_fft_conj .* img_blur_fft ./ (kernel_fft .* kernel_fft_conj + k);
img_wiener_ifft = ifft2(img_wiener_freq);

  1. 请注意,我没有在 fft2 ifft2 函数中使用size参数.在这种情况下,最好不要使用零填充图像.

  1. Notice that I do not use the size parameters to the fft2 and ifft2 functions. It is always best to not pad images with zeros in this case.

kernel 图像以非常特定的方式填充.FFT假定原点位于输入的左上像素中. fft2(kernel,dim,dim)导致用零向右和底部填充内核,但这会使内核相对于FFT的起源发生偏移.这种移位也会使去卷积图像也发生移位(仅2像素,这很难注意到,但是请查看 img_wiener_ifft-double(img)以获得OP的代码,而该代码可以看到这种移位).

The kernel image was padded in a very specific way. The FFT assumes that the origin is in the top-left pixel of the input. fft2(kernel,dim,dim) leads to padding the kernel to the right and bottom with zeros, but this leaves the kernel shifted with respect the FFT's origin. This shift causes the deconvolve image to be shifted as well (by only 2 pixels, it's hard to notice, but look at img_wiener_ifft-double(img) for OP's code and this code to see this shift).

这篇关于通过相同大小的卷积,维纳滤镜无法处理模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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