Image restoration method (matlab)

Common methods of image restoration mainly include: inverse filter restoration, Wiener filter restoration, constrained least squares restoration, Lucy-Richardson restoration and blind deconvolution restoration.

inverse filter restoration

f(x,y) represents the input image, which is an ideal image without degradation, g(x,y) is the observed image after degradation, and n(x,y) is additive noise. After Fourier transform to the frequency domain: G(u,v) = F(u,v)H(u,v)+N(u,v)

The purpose of image restoration is to obtain the estimated image F'(u,v ), making the image as close as possible to the original image F(u,v). The easiest way to restore an image is: F'(u,v) = G(u,v)/H(u,v), and then get the image through the inverse Fourier transform of F'(u,v) The estimated value of is called inverse filtering. Inverse filtering is an unconstrained restoration method. Unconstrained restoration means that in the case of degraded image G(u,v), according to some degraded model H(u,v) and noise N(u,v) Knowledge, make an estimate of the original image F'(u,v), so that some pre-determined error criterion is the mouth is small. In the process of obtaining the minimum error, there are no constraints.

When direct inverse filtering: due to the presence of noise, the degraded image formula F'(u,v) = G(u,v)+N(u,v)/H(u,v), in order to avoid H(u,v) The value of is too small, some restrictions can be added to the inverse filtering, and the restoration is only performed in the neighborhood with the root near the origin, which is called pseudo-inverse filtering

The inverse filter restores the image:

%建立函数fftfilter()进行图像的频域滤波
function Z=fftifilter(X,H)
F=fft2(X,size(H,1),size(H,2));%傅里叶变换
Z = H.*F;%滤波
Z=ifftshift(Z);
Z=abs(ifft2(Z));%傅里叶反变换
Z=Z(1:size(X,1),1:size(X,2));
end

>> I = imread('E:\persional\matlab\images\cameraman.tif');
>> I = im2double(I);
>> [m,n] = size(I);
>> M=2*m;N=2*n;
>> u=-m/2:m/2-1;
>> v=-n/2:n/2-1;
>> [U,V] = meshgrid(u,v);
>> D=sqrt(U.^2+V.^2);
>> D0=130;%截止频率
>> H=exp(-(D.^2)./(2*(D0^2)));%高斯低通滤波器
>> N=0.01*ones(size(I,1),size(I,2));
>> N=imnoise(N,'gaussian',0,0.01);%添加噪声
>> J=fftifilter(I,H)+N;%频域滤波并加噪声
>> figure,
>> subplot(221),imshow(I);
>> subplot(222),imshow(J,[ ]);
>> HC=zeros(m,n);
>> M1=H>0.1;%频率范围
>> HC(M1)=1./H(M1);
>> K=fftifilter(J,HC);%逆滤波
>> HC=zeros(m,n);
>> M2=H>0.01;
>> HC(M2)=1./H(M2);
>> L=fftifilter(J,HC);
>> subplot(223),imshow(K,[ ]);
>> subplot(224),imshow(L,[ ]);

insert image description here

Wiener filter restoration

J = deconvwnr(I,PSF,NSR)
PSF: point spread function
NSR: signal-to-noise ratio, the ratio of the signal mean to the background standard deviation

J = deconvwnr(I,PSF,NCORR,ICORR)
NCORR: autocorrelation function of noise
ICORR: autocorrelation function of original image

Restoring motion blurred images by Wiener filtering:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = rgb2gray(I);
>> I = im2double(I);
>> LEN = 25;%运动位移像素
>> THETA = 20;%运动角度
>> PSF = fspecial('motion',LEN,THETA);%产生PSF
>> J = imfilter(I,PSF,'conv','circular');%运动模糊
>> NSR = 0;
>> K = deconvwnr(J,PSF,NSR);%维纳滤波复原
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

insert image description here

Restoring noisy motion blurred images by Wiener filtering:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> LEN = 21;%运动位移像素
>> THETA = 11;%运动角度
>> PSF = fspecial('motion',LEN,THETA);
>> J = imfilter(I,PSF,'conv','circular');%通过卷积对图像进行滤波,产生模糊图像
>> noise_mean=0;%均值
>> noise_var=0.0001;%方差
>> K = imnoise(J,'gaussian',noise_mean,noise_var);%添加高斯噪声
>> NSR1=0;
>> L1 = deconvwnr(K,PSF,NSR1);%维纳滤波复原
>> NSR2=noise_var/var(I(:));
>> L2=deconvwnr(K,PSF,NSR2);%图像复原
>> figure,
>> subplot(221),imshow(I);
>> subplot(222),imshow(K);
>> subplot(223),imshow(L1);%NSR为0的复原图像
>> subplot(224),imshow(L2);%采用真实的NSR时得到复原的图像

insert image description here

Restoration from the autocorrelation information of the image:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> LEN = 20;%运动位移像素
>> THETA=10;%运动角度
>> PSF=fspecial('motion',LEN,THETA);%产生PSF
>> J = imfilter(I,PSF,'conv','circular');%运动模糊
>> noise=0.03*randn(size(I));
>> K = imadd(J,noise);%添加噪声
>> NP = abs(fft2(noise)).^2;
>> NPPower=sum(NP(:))/prod(size(noise));
>> NCORR=fftshift(real(ifft2(NP)));%噪声自相关函数
>> IP=abs(fft2(I)).^2;
>> IPower=sum(IP(:))/prod(size(I));
>> ICORR=fftshift(real(ifft2(IP)));%函数自相关函数
>> L=deconvwnr(K,PSF,NCORR,ICORR);%图像复原
>> figure,
>> subplot(221),imshow(I);%原图
>> subplot(222),imshow(J);%退化图像
>> subplot(223),imshow(K);%噪声图像
>> subplot(224),imshow(L);%图像复原

insert image description here

Constrained Least Squares Restoration

J = deconvreg(I,PSF)
J = deconvreg(I,PSF,NOISEPOWER)
J = deconvregl(I,PSF,NOISEPOWER,LRANGE)
J = deconvregl(I,PSF,NOISEPOWER,LRANGE,REGOP)
[J,LAGRA] = deconvreg(IPSF,…)
PSF: point spread function
NOISEPOWER: strength of noise, default is 0
LRANGE: search range of Lagrange operator, default is [10 -9 ,10 9 ]
REGOP: constraint operator
LAGRA: LAGRA is the final Lagrange operator

Constrained Least Square Method for Image Restoration

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> PSF=fspecial('gaussian',8,4);
>> J = imfilter(I,PSF,'conv');%图像退化
>> v=0.04;
>> K = imnoise(J,'gaussian',0,v);%添加噪声
>> NP = v*prod(size(I));
>> L = deconvreg(K,PSF,NP);%图像复原
>> figure,
>> subplot(221),imshow(I);
>> subplot(222),imshow(J);%退化图像
>> subplot(223),imshow(K);%添加噪声
>> subplot(224),imshow(L);

insert image description here

Image restoration by Lagrange operator:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> PSF=fspecial('gaussian',12,6);
>> J = imfilter(I,PSF,'conv');
>> v=0.04;
>> K = imnoise(J,'gaussian',0,v);
>> NP = v*prod(size(I));
>> [L,LAGRA]=deconvreg(K,PSF,NP);%图像复原
>> edged=edgetaper(K,PSF);%提取边缘
>> M1=deconvreg(edged,PSF,[],LAGRA)%图像复原;
>> M2=deconvreg(edged,PSF,[],LAGRA*30);%增大拉格朗日算子
>> M3=deconvreg(edged,PSF,[],LAGRA/30);%减小拉格朗日算子
>> figure,
>> subplot(231),imshow(I);
>> subplot(232),imshow(K);
>> subplot(233),imshow(edged);
>> subplot(234),imshow(M1);
>> subplot(235),imshow(M2);
>> subplot(236),imshow(M3);

insert image description here

Lucy-Richardson Restoration

deconvlucy() uses the accelerated convergence Lucy-Richardson algorithm to restore the image

J = deconvlucy(I,PSF)
J = deconvlucy(I,PSF,NUMIT)
J = deconvlucy(I,PSF,NUMIT,DAMPAR)
J = deconvlucy(I,PSF,NUMIT,DAMPAR,WEIGHT)
J = deconvlucy(I, PSF,NUMIT,DAMPAR,WEIGHT,READOUT)
J = deconvlucy(I,PSF,NUMIT,DAMPAR,WEIGHT,READOUT,SUBSMPL)
PSF: extension function
NUMIT: number of algorithm repetitions, default value is 10
DAMPAR: deviation threshold, default value 0
WEIGHT: the weighted value of the pixel, the default is the initial value of the original image
READOUT: noise matrix, the default value is 0
SUBSMPL: sampling time, the default value is 1

Motion blurred image:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> LEN = 30;
>> THETA = 20;
>> PSF = fspecial('motion',LEN,THETA);
>> J = imfilter(I,PSF,'circular','conv');%图像退化
>> K = deconvlucy(J,PSF,5);%复原,5次迭代
>> L = deconvlucy(J,PSF,15);%复原,15次迭代
>> figure,
>> subplot(221),imshow(I);
>> subplot(222),imshow(J);%图形退化
>> subplot(223),imshow(K);
>> subplot(224),imshow(L);

insert image description here

Gaussian noise:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> PSF = fspecial('gaussian',7,10);
>> v = 0.0001>> J = imnoise(imfilter(I,PSF),'gaussian',0,v);%高斯噪声
>> WT = zeros(size(I));
>> WT(5:end-4,5,5:end-4);%像素权重
>> K = deconvlucy(J,PSF,20,sqrt(v));%图像复原
>> L = deconvlucy(J,PSF,20,sqrt(v),WT);
>> figure,
>> subplot(221),imshow(I);
>> subplot(222),imshow(J);
>> subplot(223),imshow(K);
>> subplot(224),imshow(L);

insert image description here

Blind Deconvolution Restoration

The previous image restoration method needs to know the PSF of the degraded image in advance, and the blind deconvolution restoration method does not need to know the PSF, but estimates the PSF. The advantage of the blind deconvolution restoration algorithm is that it can still be restored without prior knowledge of the degraded image.

[J,PSF] = deconvblind(I,INITPSF)
[J,PSF] = deconvblind(I,INITPSF,NUMIT)
[J,PSF] = deconvblind(I,INITPSF,NUMIT,DAMPAR)
[J,PSF] = deconvblind( I,INITPSF,NUMIT,DAMPAR,WEIGHT)
[J,PSF] = deconvblind(I,INITPSF,NUMIT,DAMPAR,WEIGHT,READOUT)
INITPSF: estimated value of PSF input parameter INITPSF
NUMIT: number of repetitions
DAMPAR: shift threshold, The default value is 0
WEIGHT: pixel weighted value, the default is the value of the original image
READOUT: noise matrix

Motion blurred image:

>> I = imread('E:\persional\matlab\images\lena.bmp');
>> I = im2double(I);
>> LEN=20;
>> THETA=20;
>> PSF=fspecial('motion',LEN,THETA);
>> J = imfilter(I,PSF,'circular','conv');%运动模糊
>> INITPSF=ones(size(PSF));%输入估计值
>> [K,PSF2] = deconvblind(J,INITPSF,30);%图像复原
>> figure,
>> subplot(221),imshow(PSF,[]);%显示PSF
>> subplot(222),imshow(PSF2,[]);%显示估计的PSF
>> subplot(223),imshow(J);%退化图像
>> subplot(224),imshow(K);%复原图像

insert image description here

Restoring a degraded image:

>> I = checkerboard(8);
>> PSF = fspecial('gaussian',7,10);
>> v = 0.001;
>> J = imnoise(imfilter(I,PSF),'gaussian',0,v);%添加高斯噪声
>> INITPPSF = ones(size(PSF));%输入估计值
>> WT = zeros(size(I));
>> WT(5:end-4,5:end-4)=1;:
>> [K,PSF2] = deconvblind(J,INITPPSF,20,10*sqrt(v),WT);%图像复原
>> figure,
>> subplot(131),imshow(I);
>> subplot(132),imshow(J);
>> subplot(133),imshow(K);

insert image description here

Guess you like

Origin blog.csdn.net/weixin_56260304/article/details/127461594