You are on page 1of 14

GAUSSIAN FILTER FOR BLURRING

J=imread('test1.tif');
I=rgb2gray(J);
figure(1);subplot(2,3,1);
imshow(I); title('original image');

%¸ß˹ģºý
siz = (size(I)-1)/2;
std = 2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
arg = -((x.*x + y.*y)/(std*std));
H = (exp(arg));
H(H<eps*max(H(:))) = 0;
sumh = sum(H(:)); %¹éÒ»»¯Òò×ÓK
if sumh ~= 0,
H = H/sumh; %¹éÒ»»¯
end;

%H=fspecial('gaussian',10,2);%²úÉú¸ß˹ģºý½µÎöº¯Êý

Gaussian = imfilter(I,H,'replicate');

figure(1);subplot(2,3,2);
imshow(Gaussian);title('blurred image');

REGULARISATION APPROACH
%******************************%
%* standard regularisation *%
%******************************%
clear all;
close all;
J=imread('test4.tif');
I=rgb2gray(J);
figure(1);subplot(2,3,1);
imshow(I); title('original image');

%construction of LR image
siz = (size(I)-1)/2;
std = 2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
arg = -((x.*x + y.*y)/(std*std)).^1.5;
H = (exp(arg));
H(H<eps*max(H(:))) = 0;
sumh = sum(H(:));
if sumh ~= 0,
H = H/sumh;
end;

%H=fspecial('gaussian',10,2);
Gaussian = imfilter(I,H,'replicate');

figure(1);subplot(2,3,2);
imshow(Gaussian);title('blurred image');

Gaussian_G=imnoise(Gaussian,'gaussian',0,0.005);
%Gaussian_G=imnoise(Gaussian,'salt & pepper',0.005);

figure(1);subplot(2,3,3);
imshow(Gaussian_G);title('image with salt and pepper noise');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

blurimage=Gaussian_G;
[row,col,raw]=size(blurimage);

%%%%%%%%%%%%%%%%%%%%%
N1=row;
N2=col;
N3=raw;
T=zeros(N1,N2);
x0=N1/2;y0=N2/2;
for re=1:N1
for im=1:N2
ta=cos( 2*pi*( (re-1)*x0+(im-1)*y0 )/N1 );
tb=-sin(2*pi*( (re-1)*x0+(im-1)*y0 )/N2 );
T(re,im)=complex(ta,tb);
end
end

p=[0 -1 0;-1 4 -1;0 -1 0];


FFT_p=fft2(p,row,col);
FFT_blurimage=fft2(blurimage,row,col);
FFT_G=fft2(Gaussian_G,row,col);
FFT_H=fft2(H,row,col);
FFT_H=FFT_H.*T;
CONJ_FFT_H=conj(FFT_H);
det_FFT_H=abs(FFT_H);
det_FFT_p=abs(FFT_p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

X1=Gaussian_G;
d=0.000001;
Y=Gaussian_G;
Q=[0,-1,0;-1,4,-1;0,-1,0];
mark=0;

A =H;
%B =imfilter(X1,Q,'replicate')
N =imfilter(X1,A,'replicate');
a1=norm((double(Y)-double(N)),2).^2;

a2=norm(double(Y),2).^2;
%a3=norm(double(X1),2).^2;
m=0.01;
c=0.00001;
alfa=log(m*a1/(a2+c)+1);
%alfa=0.1;

FFT_X1=fft2(X1,row,col);
FFT_X1_t=CONJ_FFT_H.*FFT_X1;

FFT_object=FFT_X1_t+CONJ_FFT_H.*FFT_blurimage-
FFT_X1_t.*(det_FFT_H.^2+alfa.*det_FFT_p.^2);
%FFT_object=FFT_X1_t+CONJ_FFT_H.*FFT_blurimage-
FFT_X1_t.*(det_FFT_H.^2+alfa);

%FFT_object=(CONJ_FFT_H.*FFT_blurimage)./(det_FFT_H.^2+alfa*det_FFT_p.^2);

object=abs(ifft2(FFT_object));

%t=X1;
%X2=mod(X2,Z);
%X1=object;
%end

object_max=max(max(object));
object_min=min(min(object));
object=(object-object_min)*255/(object_max-object_min);
resultim = uint8(object);

%%%%%%%%%%%
[L1,L2]=size(I)
dx=norm((double(resultim)-double(I)),2).^2
PSNR=10*log((255*255*L1*L2)/dx)

%%%%%%%%%
subplot(2,3,4);
figure(1);imshow(resultim,[0,255]);
promp=['reconstructed image',10,'PSNR=' num2str(PSNR)];
title(promp);

ITERATIVE REGULARISATION (REGULARISING ML MAP)


%**********************************%
%* iterative regularisation *%
%**********************************%
clear all;
close all;
J=imread('test2.tif');
I=rgb2gray(J);
figure(1);subplot(2,3,1);
imshow(I); title('original image');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%constructing LR image
siz = (size(I)-1)/2;
std = 2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
arg = -((x.*x + y.*y)/(std*std)).^1.5;
H = (exp(arg));
H(H<eps*max(H(:))) = 0;
sumh = sum(H(:));
if sumh ~= 0,
H = H/sumh;
end;

%H=fspecial('gaussian',10,2);

Gaussian = imfilter(I,H,'replicate');
figure(1);subplot(2,3,2);
imshow(Gaussian);title('blurred image');

Gaussian_G=imnoise(Gaussian,'gaussian',0,0.005);
%Gaussian_G=imnoise(Gaussian,'salt & pepper',0.005);
figure(1);subplot(2,3,3);
imshow(Gaussian_G);title('degraded image with salt and pepper noise');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
blurimage=Gaussian_G;
[row,col,raw]=size(blurimage);

N1=row;
N2=col;
N3=raw;
T=zeros(N1,N2);
x0=N1/2;y0=N2/2;
for re=1:N1
for im=1:N2
ta=cos( 2*pi*( (re-1)*x0+(im-1)*y0 )/N1 );
tb=-sin(2*pi*( (re-1)*x0+(im-1)*y0 )/N2 );
T(re,im)=complex(ta,tb);
end
end

p=[0 -1 0;-1 4 -1;0 -1 0];


FFT_p=fft2(p,row,col);
FFT_blurimage=fft2(blurimage,row,col);
FFT_G=fft2(Gaussian_G,row,col);
FFT_H=fft2(H,row,col);
FFT_H=FFT_H.*T;
CONJ_FFT_H=conj(FFT_H);
det_FFT_H=abs(FFT_H);
det_FFT_p=abs(FFT_p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X1=Gaussian_G;
d=0.000001;
m=0.01;
c=0.00001;
Y=Gaussian_G;
Q=[0,-1,0;-1,4,-1;0,-1,0];
mark=0;

for k=1:20

A =H;
B =imfilter(Y,Q,'replicate')
N =imfilter(X1,A,'replicate');
a1=norm((double(Y)-double(N)),2).^2;
a2=norm(double(Y),2).^2;
%a3=norm(double(X1),2).^2;

%alfa=log(m*a1/(a2)+1);
%alfa=log(m*a1/(a2+c)+1);
alfa=(15*a1)/a2;

xx(k)=k;
yy(k)=alfa;

FFT_X1=fft2(X1,row,col);
FFT_X1_t=CONJ_FFT_H.*FFT_X1;
FFT_object=FFT_X1_t+CONJ_FFT_H.*FFT_blurimage-
FFT_X1_t.*(det_FFT_H.^2+alfa*det_FFT_p.^2);

%FFT_object=(CONJ_FFT_H.*FFT_blurimage)./(det_FFT_H.^2+alfa*det_FFT_p.^2);
object=abs(ifft2(FFT_object));

object_max=max(max(object));
object_min=min(min(object));
object=(object-object_min)*255/(object_max-object_min);
object = uint8(object);

X2=object;
t=X1;
X1=X2;
diff=(norm(double(X2)-double(t),2).^2)/((norm(double(t),2)).^2)
if (mark==0)
if (diff <=d)
mark=k;
resultim=object;
end

end

end
if (mark==0)
mark=50;
resultim=object;
end

[L1,L2]=size(I)
dx=norm((double(resultim)-double(I)),2).^2
PSNR=10*log((255*255*L1*L2)/dx)

subplot(2,3,4);
figure(1);imshow(resultim,[0,255]);
promp=['reconstruction ',10,'iterative' num2str(mark),10,'PSNR='
num2str(PSNR)];
title(promp);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f=resultim;
f=double(f);
[m,n]=size(f);
g=f;
g1=f;
g0=f;

for i=2:m-1
for j=2:n-1
g00(i,j)=g(i+1,j)+g(i-1,j)+g(i,j-1)+g(i,j+1)-4*g(i,j);
%+g(i+1,j+1)+g(i+1,j-1)+g(i-1,j+1)+g(i-1,j-1)
end
end
for i=1:m-2
for j=1:n-2
g0(i,j)=f(i,j)-g00(i,j);
end
end
g0=uint8(g0);
subplot(2,3,5);
figure(1);imshow(g0);title('regularisation');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

finalim=uint8((double(resultim)+(double(g0)-double(resultim))/2));

[L1,L2]=size(I)
dx=norm((double(finalim)-double(I)),2).^2
PSNR1=10*log((255*255*L1*L2)/dx)
promp1=['reconstruction iterative_regularisation',10,'PSNR='
num2str(PSNR1)];
figure(1);subplot(2,3,6);
imshow(finalim);title(promp1);

PROPOSED ALGORITHM (NOISE FACTOR CONSIDERATION)


%* iterative_adaptive regularisation (proposed algorithm) *%
%*****************************************%
clear all;
close all;
J=imread('test1.tif');
I=rgb2gray(J);
figure(1);subplot(2,2,1);
imshow(I); title('original image');

siz = (size(I)-1)/2;
std = 2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
arg = -((x.*x + y.*y)/(std*std)).^1.5;
H = (exp(arg));
H(H<eps*max(H(:))) = 0;
sumh = sum(H(:));
if sumh ~= 0,
H = H/sumh;
end;

%H=fspecial('gaussian',10,2);

Gaussian = imfilter(I,H,'replicate');

figure(1);subplot(2,2,2);
imshow(Gaussian);title('blurred image');

Gaussian_G=imnoise(Gaussian,'gaussian',0,0.005);
%Gaussian_G=imnoise(Gaussian,'salt & pepper',0.005)

figure(1);subplot(2,2,3);
imshow(Gaussian_G);title('degradedimage with salt and pepper');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

blurimage=Gaussian_G;

[row,col,raw]=size(blurimage);

%figure;
%imshow(blurimage,[0,255]);
%title('blur image');

N1=row;
N2=col;
N3=raw;
T=zeros(N1,N2);
x0=N1/2;y0=N2/2;
for re=1:N1
for im=1:N2
ta=cos( 2*pi*( (re-1)*x0+(im-1)*y0 )/N1 );
tb=-sin(2*pi*( (re-1)*x0+(im-1)*y0 )/N2 );
T(re,im)=complex(ta,tb);
end
end

p=[0 -1 0;-1 4 -1;0 -1 0];


FFT_p=fft2(p,row,col);

FFT_blurimage=fft2(blurimage,row,col);
FFT_G=fft2(Gaussian_G,row,col);
FFT_H=fft2(H,row,col);
FFT_H=FFT_H.*T;

CONJ_FFT_H=conj(FFT_H);
det_FFT_H=abs(FFT_H);
det_FFT_p=abs(FFT_p);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X1=Gaussian_G;
d=0.000001;
m=0.01;
c=0.00001;
Y=Gaussian_G;
Q=[0,-1,0;-1,4,-1;0,-1,0];
mark=0;

for k=1:30

A =H;
%B =imfilter(X1,Q,'replicate')

N =imfilter(X1,A,'replicate');
a1=norm((double(Y)-double(N)),2).^2;

a2=norm(double(Y),2).^2;
%a3=norm(double(X1),2).^2;

%alfa=log(m*a1/(a2)+1);
%alfa=log(m*a1/(a2+c)+1);
alfa=(15*a1)/a2;

%*****************************%
%* adaptive regularisation *%
%*****************************%
c=cov(double(X1));
c=abs(c);
maxcc=max(max(c/a1));
for i=1:row
for j=1:col
cc(i,j)=c(i,j)/a1;
alfanew(i,j)=alfa*(1-(cc(i,j)/maxcc));
end
end

FFT_X1=fft2(X1,row,col);
FFT_X1_t=CONJ_FFT_H.*FFT_X1;
FFT_object=FFT_X1_t+CONJ_FFT_H.*FFT_blurimage-
FFT_X1_t.*(det_FFT_H.^2+alfanew.*det_FFT_p.^2);

%FFT_object=(CONJ_FFT_H.*FFT_blurimage)./(det_FFT_H.^2+alfa*det_FFT_p.^2);

object=abs(ifft2(FFT_object));

%±ê¶¨
object_max=max(max(object));
object_min=min(min(object));
object=(object-object_min)*255/(object_max-object_min);

object = uint8(object);

X2=object;
t=X1;
X1=X2;

if (mark==0)
if
(((norm(double(X2)-double(t),2).^2)/(norm(double(t),2).^2))<=d)
mark=k;
resultim=object;
break;
end

end

end
if (mark==0)
mark=50;
resultim=object;
end
[L1,L2]=size(I)
dx=norm((double(resultim)-double(I)),2).^2
PSNR=10*log((255*255*L1*L2)/dx)

subplot(2,2,4);
figure(1);imshow(resultim,[0,255]);
promp=['reconstructed image',10,'proposed algorithm'
num2str(mark),10,'PSNR=' num2str(PSNR)];
title(promp);

imwrite(resultim,'result02.tif','tif');

WAVELET TRANSFORMATION (OUR APPROACH)


clear all;
close all;
J=imread('test1.tif');
I=rgb2gray(J);
figure(1);subplot(2,3,1);
imshow(I); title('original image');

siz = (size(I)-1)/2;
std = 2;
[x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
arg = -((x.*x + y.*y)/(std*std)).^1.5;
H = (exp(arg));
H(H<eps*max(H(:))) = 0;
sumh = sum(H(:));
if sumh ~= 0,
H = H/sumh;
end;

%H=fspecial('gaussian',10,2);

Gaussian = imfilter(I,H,'replicate');

figure(1);subplot(2,3,2);
imshow(Gaussian);title('blurred image');

Gaussian_G=imnoise(Gaussian,'gaussian',0,0.005);
%Gaussian_G=imnoise(Gaussian,'salt & pepper',0.005);

figure(1);subplot(2,3,3);
imshow(Gaussian_G);title('blurred+salt and pepper');

%*********************************************************
blurimage=Gaussian_G;

[row,col,raw]=size(blurimage);
%figure;
%imshow(blurimage,[0,255]);
%title('blur image');

N1=row;
N2=col;
N3=raw;
T=zeros(N1,N2);
x0=N1/2;y0=N2/2;
for re=1:N1
for im=1:N2
ta=cos( 2*pi*( (re-1)*x0+(im-1)*y0 )/N1 );
tb=-sin(2*pi*( (re-1)*x0+(im-1)*y0 )/N2 );
T(re,im)=complex(ta,tb);
end
end

p=[0 -1 0;-1 4 -1;0 -1 0];


FFT_p=fft2(p,row,col);

FFT_blurimage=fft2(blurimage,row,col);
FFT_G=fft2(Gaussian_G,row,col);
FFT_H=fft2(H,row,col);
FFT_H=FFT_H.*T;

CONJ_FFT_H=conj(FFT_H);
det_FFT_H=abs(FFT_H);
det_FFT_p=abs(FFT_p);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X1=Gaussian_G;
d=0.000001;
mx=0.01;
cx=0.00001;
Y=Gaussian_G;
Q=[0,-1,0;-1,4,-1;0,-1,0];
mark=0;

for k=1:30
%*************************%
%* С²¨ÓòÔëÉù·Ö²¼¹À¼Æ *%
%*************************%
f=X1;
[T,R]=size(f);
SUB_T=(T)/2;
SUB_R=(R)/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
l=wfilters('db10','l'); %
db10£¨Ïûʧ¾ØΪ10)µÍͨ·Ö½âÂ˲¨Æ÷³å»÷ÏìÓ¦£¨³¤¶ÈΪ20£©
L=T-length(l);
M=R-length(l);

l_zeros=[l,zeros(1,L)]; % ¾ØÕóÐÐÊýÓëÊäÈëͼÏñÒ»Ö£¬Îª2µÄÕûÊýÃÝ
m_zeros=[l,zeros(1,M)];
h=wfilters('db10','h'); %
db10£¨Ïûʧ¾ØΪ10)¸ßͨ·Ö½âÂ˲¨Æ÷³å»÷ÏìÓ¦£¨³¤¶ÈΪ20£©
h_zeros=[h,zeros(1,L)]; % ¾ØÕóÐÐÊýÓëÊäÈëͼÏñÒ»Ö£¬Îª2µÄÕûÊýÃÝ
k_zeros=[h,zeros(1,M)];

for i=1:R; % Áб任


roww(1:SUB_T,i)=dyaddown( ifft( fft(l_zeros).*fft(f(:,i)') ) ).'; %
Ô²Öܾí»ý<->FFT
roww(SUB_T+1:T,i)=dyaddown( ifft( fft(h_zeros).*fft(f(:,i)') ) ).'; %
Ô²Öܾí»ý<->FFT
end;
for j=1:T; % Ðб任
line(j,1:SUB_R)=dyaddown( ifft( fft(m_zeros).*fft(roww(j,:)) ) ); %
Ô²Öܾí»ý<->FFT
line(j,SUB_R+1:R)=dyaddown( ifft( fft(k_zeros).*fft(roww(j,:)) ) ); %
Ô²Öܾí»ý<->FFT
end;
decompose_pic=line; % ·Ö½â¾ØÕó
% ͼÏñ·ÖΪËÄ¿é
lt_pic=decompose_pic(1:SUB_T,1:SUB_R); % ÔÚ¾ØÕó×óÉÏ·½ÎªµÍƵ·ÖÁ¿--
fi(x)*fi(y)
rt_pic=decompose_pic(1:SUB_T,SUB_R+1:R); % ¾ØÕóÓÒÉÏΪ--fi(x)*psi(y)
lb_pic=decompose_pic(SUB_T+1:T,1:SUB_R); % ¾ØÕó×óÏÂΪ--psi(x)*fi(y)
rb_pic=decompose_pic(SUB_T+1:T,SUB_R+1:R); % ÓÒÏ·½Îª¸ßƵ·ÖÁ¿--
psi(x)*psi(y)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%ÏÔʾ

figure(2);

subplot(2,2,1);
imshow(uint8(lt_pic)); % ×óÉÏ·½ÎªµÍƵ·ÖÁ¿--fi(x)*fi(y)
title('LL');
subplot(2,2,2);
imshow(uint8(rt_pic)); % ¾ØÕóÓÒÉÏΪ--fi(x)*psi(y)
title('LH');
subplot(2,2,3);
imshow(uint8(lb_pic)); % ¾ØÕó×óÏÂΪ--psi(x)*fi(y)
title('HL');
subplot(2,2,4);
imshow(uint8(rb_pic)); % ÓÒÏ·½Îª¸ßƵ·ÖÁ¿--psi(x)*psi(y)
title('HH');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Öع¹ÔëÉùͼÏñ
% construct_pic=decompose_matrix'*decompose_pic*decompose_matrix;

noise_d=min(rt_pic,min(lb_pic,rb_pic));

l_re=l_zeros(end:-1:1); % Öع¹µÍͨÂ˲¨
l_r=circshift(l_re',1)'; % λÖõ÷Õû
m_re=m_zeros(end:-1:1);
m_r=circshift(m_re',1)';
h_re=h_zeros(end:-1:1); % Öع¹¸ßͨÂ˲¨
h_r=circshift(h_re',1)'; % λÖõ÷Õû
k_re=k_zeros(end:-1:1);
k_r=circshift(k_re',1)';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
top_pic=[noise_d,noise_d]; % ͼÏñÉϰ벿·Ö
t=0;
for i=1:T; % ÐвåÖµµÍƵ
if (mod(i,2)==0)
topll(i,:)=top_pic(t,:); % żÊýÐб£³Ö
else
t=t+1;
topll(i,:)=zeros(1,R); % ÆæÊýÐÐΪÁã
end
end;
for i=1:R; % Áб任
topcl_re(:,i)=ifft( fft(l_r).*fft(topll(:,i)') )'; % Ô²Öܾí»ý<->FFT
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bottom_pic=[noise_d,noise_d]; % ͼÏñÏ°벿·Ö
t=0;
for i=1:T; % ÐвåÖµ¸ßƵ
if (mod(i,2)==0)
bottomlh(i,:)=bottom_pic(t,:); % żÊýÐб£³Ö
else
bottomlh(i,:)=zeros(1,R); % ÆæÊýÐÐΪÁã
t=t+1;
end
end;
for i=1:R; % Áб任
bottomch_re(:,i)=ifft( fft(h_r).*fft(bottomlh(:,i)') )'; % Ô²Öܾí»ý<-
>FFT
end;

construct1=bottomch_re+topcl_re; % Áб任Öع¹Íê±Ï

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
left_pic=construct1(:,1:SUB_R); % ͼÏñ×ó°ë²¿·Ö
t=0;
for i=1:R; % ÁвåÖµµÍƵ

if (mod(i,2)==0)
leftll(:,i)=left_pic(:,t); % żÊýÁб£³Ö
else
t=t+1;
leftll(:,i)=zeros(T,1); % ÆæÊýÁÐΪÁã
end
end;
for i=1:T; % Ðб任
leftcl_re(i,:)=ifft( fft(m_r).*fft(leftll(i,:)) ); % Ô²Öܾí»ý<->FFT
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
right_pic=construct1(:,SUB_R+1:R); % ͼÏñÓҰ벿·Ö

t=0;
for i=1:R; % ÁвåÖµ¸ßƵ
if (mod(i,2)==0)
rightlh(:,i)=right_pic(:,t); % żÊýÁб£³Ö
else
rightlh(:,i)=zeros(T,1); % ÆæÊýÁÐΪÁã
t=t+1;
end
end;
for i=1:T; % Ðб任
rightch_re(i,:)=ifft( fft(k_r).*fft(rightlh(i,:)) ); % Ô²Öܾí»ý<->FFT
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
construct_pic=rightch_re+leftcl_re; % Öؽ¨ÔëÉùͼÏñ
figure(1);subplot(2,3,4);
imshow(uint8(construct_pic));title('ÔëÉù·Ö²¼Í¼Ïñ');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ÇóÕýÔò»¯²ÎÊý alfa
A =H;
%B =imfilter(X1,Q,'replicate')

N =imfilter(X1,A,'replicate');
a1=norm((double(Y)-double(N)),2).^2;

a2=norm(double(Y),2).^2;
%a3=norm(double(X1),2).^2;

%alfa=log(m*a1/(a2)+1);
%alfa=log(m*a1/(a2+c)+1);
alfa=(15*a1)/a2;

%*****************%
%* ²ÎÊý×ÔÊÊÓ¦ *%
%*****************%
c=cov(double(construct_pic),0);
c=abs(c);
maxcc=max(max(c/a1));
for i=1:row
for j=1:col
cc(i,j)=c(i,j)/a1;
alfanew(i,j)=alfa*(1-(cc(i,j)/maxcc));
end
end

FFT_X1=fft2(X1,row,col);
FFT_X1_t=CONJ_FFT_H.*FFT_X1;
FFT_object=FFT_X1_t+CONJ_FFT_H.*FFT_blurimage-
FFT_X1_t.*(det_FFT_H.^2+alfanew.*det_FFT_p.^2);

%FFT_object=(CONJ_FFT_H.*FFT_blurimage)./(det_FFT_H.^2+alfa*det_FFT_p.^2);

object=abs(ifft2(FFT_object));

%±ê¶¨
object_max=max(max(object));
object_min=min(min(object));
object=(object-object_min)*255/(object_max-object_min);

object = uint8(object);

X2=object;
t=X1;
X1=X2;

if (mark==0)
if
(((norm(double(X2)-double(t),2).^2)/(norm(double(t),2).^2))<=d)
mark=k;
resultim=object;
break;%Í£Ö¹µü´úi
end
end

end
if (mark==0)
mark=50;
resultim=object;
end

%¼ÆËãÐÅÔë±È
[L1,L2]=size(I)
dx=norm((double(resultim)-double(I)),2).^2
PSNR=10*log((255*255*L1*L2)/dx)

%ÏÔʾ½á¹û
figure(1);subplot(2,3,5);
imshow(resultim,[0,255]);
promp=['Öؽ¨Í¼Ïñ',10,'µü´ú´ÎÊýΪ' num2str(mark),10,'PSNR=' num2str(PSNR)];
title(promp);

imwrite(resultim,'result03.tif','tif'); %Êä³ö½á¹û¡£

You might also like