[Image restoration] Based on matlab Wiener filter + least squares + RC motion blur image restoration [including Matlab source code 2778]

⛄1. Introduction to Constrained Least Square Filtering

1 Wiener Filter Motion Blurred Image Restoration
Wiener Filter (Wiener Filter) is a classic filtering method for image restoration, which can be used to reduce noise in blurred images and restore lost details. The following are the basic steps for blurred image restoration using Wiener filtering:

Determine the blur parameters: According to the known blur process or model, determine the blur parameters, such as the point spread function (PSF), which describes the influence of the blur process on the image.

Estimating Power Spectral Density: Calculate the power spectral density (PSD) from the frequency-domain representation (Fourier transform) of the blurred image. PSD reflects the energy distribution of each frequency component in the image.

Build a restoration filter: Build a restoration filter according to the fuzzy process and noise characteristics. The Wiener filter is defined in the frequency domain as the ratio of the inverse filter to the noise gain function. It takes into account the properties of the blurring process as well as the noise in the image.

Frequency domain filtering: Convert the blurred image to be restored to the frequency domain, and perform convolution operation with the restoration filter. This step will reduce the effect of noise and restore the .

Inverse Fourier transform: The restored spatial domain image will be obtained through the frequency domain filter transform.

2. Least squares motion blurred image restoration
Least squares image restoration is an image restoration method based on the least squares method, which aims to reconstruct clear images through optimization problems. Following are the basic steps for image restoration using least squares:

Establish a degradation model: According to the known image degradation process or degradation model, determine the corresponding mathematical description. For example, in blurring and noise restoration, convolution operations are often used to represent the blurring process and add noise models.

Determining the objective function: transforming the image restoration problem into an optimization problem of finding the optimal solution. Define an objective function that includes a data term (the difference between observation noise and the degraded model) and a regularization term (used to facilitate smoothing or other prior information), with appropriate weights.

Minimize the objective function: use the method of minimizing the objective function (such as gradient descent method, conjugate gradient method, Newton method, etc.) to find the best image restoration result. The value of the objective function is reduced by iteratively updating the pixel values ​​of the image.

Regularization parameter selection: In the regularization item, select an appropriate regularization parameter (or called regularization coefficient or smoothing parameter) to balance the trade-off between the data item and the regularization item. This requires debugging and optimization in real problems.

Rebuild Clear produces a sharp image. Fine-tuning of the image can be done through post-processing steps such as adjusting contrast and brightness.

⛄ 2. Part of the source code

%%%%%%%%%%% Design and Implementation of Blurred Image Restoration%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1. Wiener Filtering algorithm%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2. Wave constrained least squares filtering algorithm%% %%%%%%%%%%%%%%%%%%%%%%%%%%%
3. Richardson-Lucy algorithm%%%%%%%%%%%%%%%%%% %

%%%%%%%%%%% read original image %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
[FileName, FilePath ]=uigetfile(' .tif; .jpg; .png; .img;*.gif;','Please select the required image data');% select the test image
str=[FilePath FileName];% select the image path address
Ori_img = imread(str);% read image
figure(1)
subplot(331);imshow(Ori_img);title('Original image')
%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%% generate a motion blur image %%%%%%%%%%%%%%%%%%%%%%%
LEN = 27; THETA = 27; % set blur Variable
psf = fspecial('motion',LEN,THETA); % point spread function
MoHu_img = imfilter(Ori_img,psf,'conv','circular'); % generate motion blur image
subplot(332);imshow(MoHu_img); title('motion blur image');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%

%%%%%%%%%%% 1. Use the Wiener filter algorithm to restore %%%%%%%%%%%%%%%%%%%%%
SNR 0.01
Wiener_img_low = deconvwnr(MoHu_img, psf,0.01);% use Wiener filter algorithm to restore
subplot(334);imshow(Wiener_img_low);title('Wiener filter algorithm repair image K=0.01');
%SNR 0.001
Wiener_img_high = deconvwnr(MoHu_img,psf, 0.001);% Use Wiener filter algorithm to restore
subplot(335);imshow(Wiener_img_high);title('Wiener filter algorithm repair image K=0.001'); %
SNR 0.0001
Wiener_img_veryhigh = deconvwnr(MoHu_img,psf,0.0001) ;%Use Wiener filter algorithm to restore
subplot(335);imshow(Wiener_img_veryhigh);title('Wiener filter algorithm repair image K=0.001');
%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%% 2. Use the wave-constrained least-squares filtering algorithm to restore %%%%%%%%
Mini_img = deconvreg(MoHu_img, psf); %Use the wave-constrained least-squares filtering algorithm to restore
the subplot (333);imshow(Mini_img);title('Constrained least squares filter algorithm repair image');
%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%% 3. Use the Richardson-Lucy algorithm to restore%%%%%%%%%%%%
The default number of repetitions is 10
Lucy_img_10 = deconvlucy(MoHu_img,psf); % Use Richardson-Lucy The algorithm restores the default number of repetitions
subplot(337); imshow(Lucy_img_10); title('Richardson-Lucy algorithm repairs the image default');
% repetitions 30
Lucy_img_30 = deconvlucy(MoHu_img,psf,30); % uses Richardson-Lucy Algorithm restoration repetitions 30
subplot(338);imshow(Lucy_img_30);title('Richardson-Lucy algorithm repair image 30');
%Repeat times 60
Lucy_img_60 = deconvlucy(MoHu_img,psf,60); %Restore using Richardson-Lucy algorithm Repeat times 30
subplot(339);imshow(Lucy_img_60);title('Richardson-Lucy algorithm repair image 60');
%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%% save image%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
imwrite(Ori_img, 'Save test picture.jpg');
imwrite(MoHu_img,'Test picture blurred.jpg');
imwrite(Wiener_img_low,'Test picture Wiener 0.01.jpg');
imwrite(Wiener_img_high,'Test picture Wiener 0.001.jpg' );
imwrite(Wiener_img_veryhigh,'test picture Wiener 0.0001.jpg');
imwrite(Mini_img,'test picture least squares.jpg');
imwrite(Lucy_img_10,'test picture Lucy10.jpg');
imwrite(Lucy_img_30,' Test picture Lucy30.jpg');
imwrite(Lucy_img_60,'test picture Lucy60.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%

⛄3. Running results

insert image description here
insert image description here

⛄4. Matlab version and references

1 matlab version
2014a

2 References
[1] Jiang Li, Qin Fengqing, Zhang Tianqi, Wen Xingdong, He Wenjie, Wan Haofei. Constrained Least Square Filtering Realizes Defocused Blurred Image Restoration[J]. Journal of Yibin University. 2021,21(12)

3 Remarks
Introduction This part is taken from the Internet and is for reference only. If there is any infringement, please contact to delete

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/131503743