Digital image processing - image degradation (atmospheric turbulence model and motion blur model) and image restoration (inverse filtering and Wiener filtering)

1. Image degradation

In general, the degradation model of an image can be expressed as
insert image description here

Where g(x,y) represents the degraded image, h(x,y) represents the degraded model, f(x,y) represents the original image, and n(x,y) represents the noise.
In the frequency domain, it can be expressed as
insert image description here

Two common degradation models are introduced below: the atmospheric turbulence model based on the physical characteristics of atmospheric turbulence and the motion blur model.

1. Atmospheric turbulence model

Degradation model:
insert image description here

With the increase of k value, the obtained image becomes more and more blurred. In general: k=0.0025 severe turbulence; k=0.001 medium turbulence; k=0.00025 low turbulence.
Pseudo-code:
{ read the picture; convert to double type; convert to frequency domain space; move the spectrum to the center;



Use the model to perform degradation; multiply
the degraded model with the original image to obtain the degraded image;
perform inverse Fourier transform.
}

code show as below:

%% 读取图像
image=imread('demo-1.jpg');
subplot(231);
imshow(image);
title('原图像');
f=im2double(image);
 
%% 剧烈大气湍流退化模型
F=fft2(f);%换到频域,信号在低频,噪声在高频
F=fftshift(F);%频谱移到矩阵中心
%执行
[W,H]=size(F);
[u,v]=meshgrid(1:W,1:H);%生成矩阵
H_turbulence=exp(-0.0025* ( (u-W/2).^2+(v-H/2).^2).^(5/6) );
F=F.*H_turbulence;
%傅里叶反变换
X=ifftshift(F);
turimg=ifft2(X);
turimg=uint8(abs(turimg)*256);
subplot(232);
imshow(turimg);
title('退化图像');

2. Motion blur model

Degradation model:
insert image description here

Where T=1, a=0.1, b=0.1.

Additive noise - Gaussian noise:

noise=imnoise(motion_blur,'gaussian',noise_mean,noise_var);
noise_mean=0,noise_var=0.01
代码如下:
pic=imread('demo-1.jpg'); 
figure('name','demo2');
subplot(231);imshow(pic);title('原图像');
pic=im2double(pic); 
[width,height]=size(pic);
%% 运动模糊(+噪声
H_motion = fspecial('motion', 28, 90);%运动长度为28,逆时针运动角度为90°
motion_blur = imfilter(pic, H_motion, 'conv', 'circular');%卷积滤波
noise_mean=0;  %添加均值为0
noise_var=0.001; %方差为0.001的高斯噪声
motion_blur_noise=imnoise(motion_blur,'gaussian',noise_mean,noise_var);
subplot(232);imshow(motion_blur,[]);title('运动模糊');
subplot(233);imshow(motion_blur_noise,[]);title('运动模糊加噪声');

2. Image Restoration

1. Inverse filtering

The image is processed using a degradation function, followed by an appropriate additive noise to invert the filtering experiment. Once the degradation function has been obtained, an estimate of the Fourier transform of the original image is computed by dividing the Fourier transform of the degraded image by the degradation function:
insert image description here

Even if the degradation function is known, the undegraded image cannot be accurately restored; if the degradation function is 0 or a small value, the noise is
easily amplified.
Implementation idea:
Since H(0,0) is usually the highest value of H(u, v) in the frequency domain.
Therefore, by restricting the analysis to frequencies near the origin, the probability of encountering zero values ​​is reduced .
Pseudo-code:
{ Concentrate the signal spectrum in the low-frequency region, concentrate the noise in the high-frequency region; move the spectrum to the center of the matrix; take the center of the spectrum as the center, directly inverse filter internally, and assign 0 externally } The code is as follows:




%% 逆滤波复原
fourier_H=fft2(H_motion,width,height);  %统一大小
fourier_degrade_img1=fft2(motion_blur);    %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); h=fspecial('gaussian',width,5);
restore_three=imfilter(restore_one,h,'conv','circular');
subplot(234);imshow(im2uint8(restore_three),[]);title('逆滤波+运动模糊');
 
fourier_degrade_img2=fft2(motion_blur_noise); %G(u,v)=H(u,v)F(u,v)+N(u,v)
restore_two=ifft2(fourier_degrade_img2./fourier_H);
restore_four=imfilter(restore_two,h,'conv','circular');
subplot(235);imshow(im2uint8(restore_four),[]);title('逆滤波+运动模糊加噪声');

2. Wiener filter

insert image description here
insert image description here

The focus is on finding the signal-to-noise ratio.

code show as below:

%% 维纳滤波
fourier_H_motion=fft2(H_motion,width,height);  %H(u,v)
pow_H_motion=abs(fourier_H_motion).^2;   %|H(u,v)|^2
noise=motion_blur_noise-motion_blur;    %提取噪声分量
fourier_noise=fft2(noise);    % N(u,v)  噪声傅里叶变换
fourier_double_gray_pic=fft2(pic);  %F(u,v)为未经过退化的图片
nsr=abs(fourier_noise).^2./abs(fourier_double_gray_pic).^2;   %噪信比=|N(u,v)|^2/|F(u,v)|^2
H_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),时域为频域傅里叶逆变换
subplot(236);imshow(restore_with_noise,[]);title('维纳滤波')

3. Realize the result

insert image description here
insert image description here
insert image description here
insert image description here

4. Appendix

1. Picture
demo-1.jpg
Please add a picture description
demo-2.jpg
Please add a picture description
myMatlab.m

clc;        
clear;       
close all;
%% 官方运动模糊+维纳滤波
I = im2double(imread('demo-1.jpg'));
figure,subplot(2,3,1),imshow(I);
title('原图');

%运动模糊
LEN = 28;
THETA = 90;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
subplot(2,3,2),imshow(blurred);
title('运动模糊退化');

wnr1 = deconvwnr(blurred, PSF, 0);
subplot(2,3,3),imshow(wnr1);
title('运动模糊复原');

%运动模糊+噪声
noise_mean = 0;
noise_var = 0.0001;
blurred_noisy = imnoise(blurred, 'gaussian', ...
                        noise_mean, noise_var);
subplot(2,3,4),imshow(blurred_noisy)
title('运动模糊+噪声')

wnr2 = deconvwnr(blurred_noisy, PSF, 0);
subplot(2,3,5),imshow(wnr2)
title('模糊+噪声 逆滤波');
signal_var = var(I(:));
wnr3 = deconvwnr(blurred_noisy, PSF, noise_var / signal_var);
subplot(2,3,6),imshow(wnr3)
title('模糊+噪声 维纳滤波');

mymotion.m

clc;         
clear;       
close all;   
pic=imread('demo-1.jpg'); 
figure('name','demo2');
subplot(231);imshow(pic);title('原图像');
pic=im2double(pic); 
[width,height]=size(pic);

%% 运动模糊(+噪声
H_motion = fspecial('motion', 28, 90);%运动长度为28,逆时针运动角度为90°
motion_blur = imfilter(pic, H_motion, 'conv', 'circular');%卷积滤波
noise_mean=0;  %添加均值为0
noise_var=0.001; %方差为0.001的高斯噪声
motion_blur_noise=imnoise(motion_blur,'gaussian',noise_mean,noise_var);
subplot(232);imshow(motion_blur,[]);title('运动模糊');
subplot(233);imshow(motion_blur_noise,[]);title('运动模糊加噪声');

%% 逆滤波复原
fourier_H=fft2(H_motion,width,height);  %变大小
fourier_degrade_img1=fft2(motion_blur);    % G(u,v)=H(u,v)F(u,v),已知G(u,v),H(u,v),求F(u,v)
restore_1=ifft2(fourier_degrade_img1./fourier_H);  % 
h=fspecial('gaussian',width,5);
restore_2=imfilter(restore_1,h,'conv','circular');
subplot(234);imshow(im2uint8(restore_2),[]);title('逆滤波+运动模糊');

fourier_degrade_img2=fft2(motion_blur_noise); %G(u,v)=H(u,v)F(u,v)+N(u,v)
restore_3=ifft2(fourier_degrade_img2./fourier_H);
restore_4=imfilter(restore_3,h,'conv','circular');
subplot(235);imshow(im2uint8(restore_4),[]);title('逆滤波+运动模糊加噪声');

%% 维纳滤波
fourier_H_motion=fft2(H_motion,width,height);  %H(u,v)
pow_H_motion=abs(fourier_H_motion).^2;   %|H(u,v)|^2
noise=motion_blur_noise-motion_blur;    %提取噪声分量
fourier_noise=fft2(noise);    % N(u,v)  噪声傅里叶变换
fourier_double_gray_pic=fft2(pic);  %F(u,v)为未经过退化的图片
nsr=abs(fourier_noise).^2./abs(fourier_double_gray_pic).^2;   %噪信比=|N(u,v)|^2/|F(u,v)|^2
H_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),时域为频域傅里叶逆变换
subplot(236);imshow(restore_with_noise,[]);title('维纳滤波')

myturbulence.m

clc;
clear;
close all;
%% 读取图像
image=imread('demo-2.jpg');
subplot(231);
imshow(image);
title('原图像');
f=im2double(image);

%% 剧烈大气湍流退化模型
F=fft2(f);%换到频域,信号在低频,噪声在高频
F=fftshift(F);%频谱移到矩阵中心
%执行
[W,H]=size(F);
[u,v]=meshgrid(1:W,1:H);%生成矩阵
H_turbulence=exp(-0.0025* ( (u-W/2).^2+(v-H/2).^2).^(5/6) );
F=F.*H_turbulence;
%傅里叶反变换
X=ifftshift(F);
turimg=ifft2(X);
turimg=uint8(abs(turimg)*256);
subplot(232);
imshow(turimg);
title('大气湍流退化');

%% 直接逆滤波
FDeblurred=F./H;
IDeblurred=real(ifft2(ifftshift(FDeblurred)));
subplot(233), imshow(uint8(255.*mat2gray(IDeblurred)));
title('直接逆滤波');

Guess you like

Origin blog.csdn.net/qq_46056318/article/details/124102669