700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 数字图像处理-运动模糊逆滤波维纳滤波(Matlab)

数字图像处理-运动模糊逆滤波维纳滤波(Matlab)

时间:2020-11-24 12:46:39

相关推荐

数字图像处理-运动模糊逆滤波维纳滤波(Matlab)

文章目录

数字图像处理-运动模糊&逆滤波&维纳滤波(Matlab)1、对指定的一幅灰度图像,先用3*3均值滤波器进行模糊处理,形成退化图像1;再叠加椒盐噪声,形成退化图像2;再对上述退化图像1和2采用逆滤波进行复原,给出复原结果图像。分析对比在对H零点问题采用不同处理方法下的复原结果。1-1 图像退化(均值滤波+椒盐噪声)1-2 直接逆滤波还原图像1-3 去掉噪声分量逆滤波还原图像2、对一幅灰度图像进行运动模糊并叠加高斯噪声,并采用维纳滤波进行复原。2-1 图像退化(运动模糊+高斯噪声)2-2 维纳滤波(Matlab自带函数:deconvwnr)2-3 根据公式编写维纳滤波

数字图像处理-运动模糊&逆滤波&维纳滤波(Matlab)

1、对指定的一幅灰度图像,先用3*3均值滤波器进行模糊处理,形成退化图像1;再叠加椒盐噪声,形成退化图像2;再对上述退化图像1和2采用逆滤波进行复原,给出复原结果图像。分析对比在对H零点问题采用不同处理方法下的复原结果。

1-1 图像退化(均值滤波+椒盐噪声)

Matlab代码块:

%---------------------9x9均值滤波模糊处理-------------------clc; %清空控制台clear; %清空工作区close all; %关闭已打开的figure图像窗口color_pic=imread('lena512color.bmp'); %读取彩色图像gray_pic=rgb2gray(color_pic); %将彩色图转换成灰度图double_gray_pic=im2double(gray_pic); %将uint8转成im2double型便于后期计算[width,height]=size(double_gray_pic);H=fspecial('average',9); %生成9x9均值滤波器,图像更模糊,3x3几乎看不出差别degrade_img1=imfilter(double_gray_pic, H, 'conv', 'circular'); %使用卷积滤波,默认是相关滤波%--------------------在均值滤波模糊图像基础上添加椒盐噪声------------------degrade_img2=imnoise(degrade_img1,'salt & pepper',0.05); %给退化图像1添加噪声密度为0.05的椒盐噪声(退化图像2)figure('name','退化图像');subplot(2,2,1);imshow(color_pic,[]);title('原彩色图');subplot(2,2,2);imshow(double_gray_pic,[]);title('原灰度图');subplot(2,2,3);imshow(degrade_img1,[]);title('退化图像1');subplot(2,2,4);imshow(degrade_img2,[]);title('退化图像2');

运行效果:

1-2 直接逆滤波还原图像

Matlab代码块:

%-------------------------对退化图像1逆滤波复原-------------------------fourier_H=fft2(H,width,height); %注意此处必须得让H从9x9变成与原图像一样的大小此处为512x512,否则ifft2 ./部分会报错矩阵不匹配fourier_degrade_img1=fft2(degrade_img1); %相当于 G(u,v)=H(u,v)F(u,v),已知G(u,v),H(u,v),求F(u,v)restore_one=ifft2(fourier_degrade_img1./fourier_H); %因为是矩阵相除要用./ figure('name','退化图像1逆滤波复原');subplot(1,2,1);imshow(im2uint8(degrade_img1),[]);title('退化图像1');subplot(1,2,2);imshow(im2uint8(restore_one),[]);title('复原图像1');%-------------------------对退化图像2直接逆滤波复原-------------------------fourier_degrade_img2=fft2(degrade_img2); %相当于 G(u,v)=H(u,v)F(u,v)+N(u,v)restore_two=ifft2(fourier_degrade_img2./fourier_H);

运行效果:

1-3 去掉噪声分量逆滤波还原图像

Matlab代码块:

%------------------------去掉噪声分量逆滤波复原-----------------------noise=degrade_img2-degrade_img1; %提取噪声分量fourier_noise=fft2(noise); %对噪声进行傅里叶变换restore_three=ifft2((fourier_degrade_img2-fourier_noise)./fourier_H); %G(u,v)=H(u,v)F(u,v)+N(u,v),解得F(u,v)=[G(u,v)-N(u,v)]/H(u,v)figure('name','退化图像2逆滤波复原');subplot(2,2,1);imshow(double_gray_pic,[]);title('原灰度图');subplot(2,2,2);imshow(im2uint8(degrade_img2),[]);title('退化图像2');subplot(2,2,3);imshow(im2uint8(restore_two),[]);title('直接逆滤波复原');subplot(2,2,4);imshow(im2uint8(restore_three),[]);title('去掉噪声分量逆滤波复原');

运行效果:总结:逆滤波依赖噪声属性

当有噪声时,直接进行逆滤波,此时输出为:G(u,v)H(u,v)\dfrac{G(u,v)}{H(u,v)}H(u,v)G(u,v)​

G(u,v)=H(u,v)F(u,v)+N(u,v)G(u,v)=H(u,v)F(u,v)+N(u,v) G(u,v)=H(u,v)F(u,v)+N(u,v)

G(u,v)H(u,v)=F(u,v)+N(u,v)H(u,v)\dfrac{G(u,v)}{H(u,v)}=F(u,v)+\dfrac{N(u,v)}{H(u,v)} H(u,v)G(u,v)​=F(u,v)+H(u,v)N(u,v)​

从上式可见,如果H(u,v)足够小,则输出结果被噪声所支配,复原出来的图像便是一幅充满椒盐噪声的图。

所以当我们已知道所加的噪声信号时,还原出的信号为F(u,v)=G(u,v)−N(u,v)H(u,v)F(u,v)=\dfrac{G(u,v)-N(u,v)}{H(u,v)}F(u,v)=H(u,v)G(u,v)−N(u,v)​,即如果不知道噪声信号,则清晰还原困难。

2、对一幅灰度图像进行运动模糊并叠加高斯噪声,并采用维纳滤波进行复原。

2-1 图像退化(运动模糊+高斯噪声)

Matlab代码块:

% ----------------2、对一幅灰度图像进行运动模糊并叠加高斯噪声,并采用维纳滤波进行复原-------------clc; %清空控制台clear; %清空工作区close all; %关闭已打开的figure图像窗口color_pic=imread('lena512color.bmp'); %读取彩色图像gray_pic=rgb2gray(color_pic); %将彩色图转换成灰度图double_gray_pic=im2double(gray_pic); %将uint8转成im2double型便于后期计算[width,height]=size(double_gray_pic);%-------------------------添加运动模糊----------------------H_motion = fspecial('motion', 18, 90);%运动长度为18,逆时针运动角度为90°motion_blur = imfilter(double_gray_pic, H_motion, 'conv', 'circular');%卷积滤波noise_mean=0; %添加均值为0noise_var=0.001; %方差为0.001的高斯噪声motion_blur_noise=imnoise(motion_blur,'gaussian',noise_mean,noise_var);%添加均值为0,方差为0.001的高斯噪声figure('name','运动模糊加噪');subplot(1,2,1);imshow(motion_blur,[]);title('运动模糊');subplot(1,2,2);imshow(motion_blur_noise,[]);title('运动模糊添加噪声');

运行效果:

2-2 维纳滤波(Matlab自带函数:deconvwnr)

函数参数介绍:

J = deconvwnr(I,PSF,NSR) deconvolves image I using the Wiener filter algorithm, returning deblurred image J. Image I can be an N-dimensional array. PSF is the point-spread function with which I was convolved. NSR is the noise-to-signal power ratio of the additive noise. NSR can be a scalar or a spectral-domain array of the same size as I. Specifying 0 for the NSR is equivalent to creating an ideal inverse filter.

Matlab代码块:

%----------------------------维纳滤波matlab自带函数deconvwnr-------------------------restore_ignore_noise = deconvwnr(motion_blur_noise, H_motion, 0); %nsr=0,忽视噪声signal_var=var(double_gray_pic(:));estimate_nsr=noise_var/signal_var; %噪信比估值restore_with_noise=deconvwnr(motion_blur_noise,H_motion,estimate_nsr); %信号的功率谱使用图像的方差近似估计figure('name','函数法维纳滤波');subplot(1,2,1);imshow(im2uint8(restore_ignore_noise),[]);title('忽视噪声直接维纳滤波(nsr=0),相当于逆滤波');subplot(1,2,2);imshow(im2uint8(restore_with_noise),[]);title('考虑噪声维纳滤波');

运行效果:

2-3 根据公式编写维纳滤波

公式原理:Matlab代码块:

%---------------------------公式法----------------------------fourier_H_motion=fft2(H_motion,width,height); %H(u,v)pow_H_motion=abs(fourier_H_motion).^2; %|H(u,v)|^2noise=motion_blur_noise-motion_blur; %提取噪声分量fourier_noise=fft2(noise); % N(u,v) 噪声傅里叶变换fourier_double_gray_pic=fft2(double_gray_pic); %F(u,v)为未经过退化的图片nsr=abs(fourier_noise).^2./abs(fourier_double_gray_pic).^2; %噪信比=|N(u,v)|^2/|F(u,v)|^2H_w=1./fourier_H_motion.*pow_H_motion./(pow_H_motion+nsr); %H_w(u,v)=1/H(u,v)*|H(u,v)|^2/[|H(u,v)|^2+NSR] fourier_motion_blur_noise=fft2(motion_blur_noise); %G(u,v)restore_with_noise=ifft2(fourier_motion_blur_noise.*H_w); %输出频域=G(u,v)H_w(u,v),时域为频域傅里叶逆变换figure('name','公式法维也纳滤波');subplot(1,2,1);imshow(motion_blur_noise,[]);title('运动模糊添加噪声')subplot(1,2,2);imshow(restore_with_noise,[]);title('维也纳滤波')

运行效果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。