📄 image_demo.m
字号:
echo on
%Deblurring Images Using the Wiener Filter
pause
%Step 1: Read in Images
I = imread('flowers.tif');
I = I(10+[1:256],222+[1:256],:);
figure;imshow(I);title('Original Image');
%Step 2: Simulate a Motion Blur
LEN = 31;
THETA = 11;
PSF = fspecial('motion',LEN,THETA);
Blurred = imfilter(I,PSF,'circular','conv');
figure; imshow(Blurred);
title('Blurred');
%Step 3: Restore the Blurred Image
%The first restoration, wnr1 , uses the true PSF, created in Step 2.
wnr1 = deconvwnr(Blurred,PSF);
figure;imshow(wnr1);
title('Restored, True PSF');
%The second restoration, wnr2 , uses an estimated PSF that simulates motion
%twice as long as the blur length (LEN).
wnr2 = deconvwnr(Blurred,fspecial('motion',2*LEN,THETA));
figure;imshow(wnr2);
title('Restored, "Long" PSF');
%The third restoration, wnr3 , uses an estimated PSF that simulates an angle of the motion
%twice as steep as the blur angle
wnr3 = deconvwnr(Blurred,fspecial('motion',LEN,2*THETA));
figure;imshow(wnr3);
title('Restored, Steep');
%Step 4: Simulate Additive Noise
noise = 0.1*randn(size(I));
BlurredNoisy = imadd(Blurred,im2uint8(noise));
figure;imshow(BlurredNoisy);title('Blurred & Noisy');
%Step 5: Restore the Blurred and Noisy Image
wnr4 = deconvwnr(BlurredNoisy,PSF);
figure;imshow(wnr4);
title('Inverse Filtering of Noisy Data');
%To control the noise amplification, provide the noise-to-signal power ratio, NSR .
NSR = sum(noise(:).^2)/sum(im2double(I(:)).^2);
wnr5 = deconvwnr(BlurredNoisy,PSF,NSR);
figure;imshow(wnr5);
title('Restored with NSR');
%Vary the NSR value to affect the restoration results. The small NSR value amplifies noise.
wnr6 = deconvwnr(BlurredNoisy,PSF,NSR/2);
figure;imshow(wnr6);
title('Restored with NSR/2');
%Step 6: Use Autocorrelation to Improve Image Restoration
%To improve the restoration of the blurred and noisy images, supply the full autocorrelation
%function(ACF) for the noise, NCORR , and the signal, ICORR .
NP = abs(fftn(noise)).^2;
NPOW = sum(NP(:))/prod(size(noise)); % noise power
NCORR = fftshift(real(ifftn(NP))); % noise ACF, centered
IP = abs(fftn(im2double(I))).^2;
IPOW = sum(IP(:))/prod(size(I)); % original image power
ICORR = fftshift(real(ifftn(IP))); % image ACF, centered
wnr7 = deconvwnr(BlurredNoisy,PSF,NCORR,ICORR);
figure;imshow(wnr7);
title('Restored with ACF');
%Explore the restoration given limited statistical information: the power of the noise, NPOW ,
%and a 1-dimensional autocorrelation function of the true image, ICORR1 .
ICORR1 = ICORR(:,ceil(size(I,1)/2));
wnr8 = deconvwnr(BlurredNoisy,PSF,NPOW,ICORR1);
figure;imshow(wnr8);
title('Restored with NP & 1D-ACF');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -