Clc ; Clear ; Close all ; % % Read Image f =imread ( ‘ Cameraman . tif ‘ ) ; f = im2double (f) ; % % Apply Motion Filter MotionLength = 7 ; MotionAngle = 45 ; PSF = fspecial ( ‘ motion ‘ , MotionLength , MotionAngle ) ; g1 = imfilter ( f , PSF) ; % % Add Noise NoiseMean = 0 ; NoiseVar = 0 . 01 ; g2 = imnoise ( g1 , ‘gaussian ‘ , NoiseMean , NoiseVar ) ; % % Wiener Deconvolution % % Results figure ; subplot ( 2 , 2 , 1 ) ; imshow ( f ) ; title ( ‘ Original Image ‘ ) ; subplot ( 2 , 2 , 2 ) ; imshow ( g1) ; title ( ‘ Blurred Image ‘ ) ; subplot ( 2 , 2 , 3) ; imshow ( g2) ; title ( ‘ Blurred and Noisey Image ‘ ) ;
% % Wiener Deconvolution % ImageVar = Var (f(:)) ; % NSPR = NoiseVar ; Fhat 1 = deconvwnr (g2 , PSF , 0 ) ; % % Results figure ; subplot ( 2 , 3 , 1 ) ; imshow ( f ) ; title ( ‘ Original Image ‘ ) ; subplot ( 2 , 3 , 2 ) ; imshow ( g1) ; title ( ‘ Blurred Image ‘ ) ; subplot ( 2 , 3 , 3) ; imshow ( g2) ; title ( ‘ Blurred and Noisey Image ‘ ) ; subplot ( 2 , 3 , 4) ; imshow ( fhat1 ) ; title ( ‘ Recovered Image ( NPSR = 0 ) ‘ ) ;
% % Add Noise NoiseMean = 0 ; NoiseVar = 0 . 001 ; g2 = imnoise ( g1 , ‘gaussian ‘ , NoiseMean , NoiseVar ) ; % % Wiener Deconvolution NSPR1 = 0 ; Fhat 1 = deconvwnr (g2 , PSF , NSPR1 ) ; ImageVar = Var (f (:) ) ; NSPR2 = NoiseVar / ImageVar ; Fhat2 = deconvwnr (g2 , PSF , NSPR2 ) ; % % Results figure ; subplot ( 2 , 3 , 1 ) ; imshow ( f ) ; title ( ‘ Original Image ‘ ) ; subplot ( 2 , 3 , 2 ) ; imshow ( g1) ; title ( ‘ Blurred Image ‘ ) ; subplot ( 2 , 3 , 3) ; imshow ( g2) ; title ( ‘ Blurred and Noisey Image ‘ ) ; subplot ( 2 , 3 , 4) ; imshow ( fhat1 ) ; title ( ‘ Recovered Image ( NPSR = 0 ) ‘ ) ; subplot ( 2 , 3 , 5) ; imshow ( fhat2 ) ; title ( [ ‘ Recovered Image ( NPSR = ‘ num2str ( NSPR2) ‘ ) ‘ ] ) ;
% % Wiener Deconvolution NSPR1 = 0 ; Fhat 1 = deconvwnr (g2 , PSF , NSPR1 ) ; ImageVar = Var (f (:) ) ; NSPR2 = NoiseVar / ImageVar ; Fhat2 = deconvwnr (g2 , PSF , NSPR2 ) ; NSPR3 = 0 .05 ; Fhat3 = deconvwnr (g2 , PSF , NSPR3 ) ; % % Results figure ; subplot ( 2 , 3 , 1 ) ; imshow ( f ) ; title ( ‘ Original Image ‘ ) ; subplot ( 2 , 3 , 2 ) ; imshow ( g1) ; title ( ‘ Blurred Image ‘ ) ; subplot ( 2 , 3 , 3) ; imshow ( g2) ; title ( ‘ Blurred and Noisey Image ‘ ) ; subplot ( 2 , 3 , 4) ; imshow ( fhat1 ) ; title ( ‘ Recovered Image ( NPSR = 0 ) ‘ ) ; subplot ( 2 , 3 , 5) ; imshow ( fhat2 ) ; title ( [ ‘ Recovered Image ( NPSR = ‘ num2str ( NSPR2) ‘ ) ‘ ] ) ; subplot ( 2 , 3 , 6) ; imshow ( fhat3 ) ; title ( [ ‘ Recovered Image ( NPSR = ‘ num2str ( NSPR3) ‘ ) ‘ ] ) ;
SN = abs (fft2 (g2 – g1)) . ^2 ; NCORR = fftshift (real (ifft2 (SN)) ; SF = abs (fft2(f)) . ^2 ; FCORR = fftshift (real (ifft2 (SF))) ; NSPR = NCORR . / FCORR ; Fhat3 = deconvwnr ( g2 , PSF , NCORR , FCORR ) ;
PSF2 = fspecial (‘gaussian ‘ , 60 , 10 ) ; Fhat4 = edgetaper (fhat3 , PSF2 ) ;