X=imread('lena128.bmp');
iterative_number=500;
t1=clock;
photo=zeros(128,128);
%%%循环1%%%
image=X(1:64,1:64);
[M,N]=size(image);
K_thmin=0;
%K_thmax=max(M,N)-1;
K_thmax=179;
K_umin=0;
K_umax=M;
K_vmin=0;
K_vmax=N;
K_sxmin=0;
K_sxmax=round(log2(M));
K_symin=0;
K_symax=round(log2(N));
image_reconstruct=zeros(M,N);
image_r=image;
%image_reconstruct=(1/(M*N))*sum(sum(image));
%image_r=image-image_reconstruct;
result=zeros(6,iterative_number);
for n=1:iterative_number
[proj,u_re,v_re,sx_re,sy_re,K_re]=GAS(image_r,M,N,K_thmin,K_thmax,K_umin,K_umax,K_vmin,K_vmax,K_sxmin,K_sxmax,K_symin,K_symax);
result(1,n)=proj;
result(2,n)=u_re;
result(3,n)=v_re;
result(4,n)=sx_re;
result(5,n)=sy_re;
result(6,n)=K_re;
if(sx_re<M/10&&sy_re<N/10)
sx_left=u_re-2*sx_re;
sy_left=v_re-2*sy_re;
sx_right=u_re+2*sx_re;
sy_right=v_re+2*sy_re;
if(sx_left<1)
sx_left=1;
end
if(sy_left<1)
sy_left=1;
end
if(sx_right>M)
sx_right=M;
end
if(sy_right>N)
sy_right=N;
end
g=zeros(M,N);
for X=sx_left-1:sx_right-1
for Y=sy_left-1:sy_right-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
g(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
elseif (sx_re>M/4&&sy_re>N/4)
sx_re=sx_re/2;
sy_re=sy_re/2;
for X=0:M-1
for Y=0:N-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
gr(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
x=0:N-1;
y=0:M-1;
xi=0:.5:N-1;
yi=0:.5:M-1;
[XI YI]=meshgrid(xi,yi);
z=interp2(x,y,gr,XI,YI);
g=z((M/2+1):(3*M/2),(N/2+1):(3*N/2));
else
for X=0:M-1
for Y=0:N-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
g(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
end
g=g./sqrt(sum(sum(g.*g)));
image_reconstruct=image_reconstruct+proj*g;
image_r=double(image_r)-proj*g;
n;
end
%X=imread('lena128.bmp');
%imshow(X);
%figure;
I1=mat2gray(image_reconstruct);
%imshow(I1);
photo(1:64,1:64)=I1;
%%%循环2%%%
X=imread('lena128.bmp');
image=X(65:128,1:64);
[M,N]=size(image);
K_thmin=0;
%K_thmax=max(M,N)-1;
K_thmax=179;
K_umin=0;
K_umax=M;
K_vmin=0;
K_vmax=N;
K_sxmin=0;
K_sxmax=round(log2(M));
K_symin=0;
K_symax=round(log2(N));
image_reconstruct=zeros(M,N);
image_r=image;
%image_reconstruct=(1/(M*N))*sum(sum(image));
%image_r=image-image_reconstruct;
result=zeros(6,iterative_number);
for n=1:iterative_number
[proj,u_re,v_re,sx_re,sy_re,K_re]=GAS(image_r,M,N,K_thmin,K_thmax,K_umin,K_umax,K_vmin,K_vmax,K_sxmin,K_sxmax,K_symin,K_symax);
result(1,n)=proj;
result(2,n)=u_re;
result(3,n)=v_re;
result(4,n)=sx_re;
result(5,n)=sy_re;
result(6,n)=K_re;
if(sx_re<M/10&&sy_re<N/10)
sx_left=u_re-2*sx_re;
sy_left=v_re-2*sy_re;
sx_right=u_re+2*sx_re;
sy_right=v_re+2*sy_re;
if(sx_left<1)
sx_left=1;
end
if(sy_left<1)
sy_left=1;
end
if(sx_right>M)
sx_right=M;
end
if(sy_right>N)
sy_right=N;
end
g=zeros(M,N);
for X=sx_left-1:sx_right-1
for Y=sy_left-1:sy_right-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
g(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
elseif (sx_re>M/4&&sy_re>N/4)
sx_re=sx_re/2;
sy_re=sy_re/2;
for X=0:M-1
for Y=0:N-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
gr(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
x=0:N-1;
y=0:M-1;
xi=0:.5:N-1;
yi=0:.5:M-1;
[XI YI]=meshgrid(xi,yi);
z=interp2(x,y,gr,XI,YI);
g=z((M/2+1):(3*M/2),(N/2+1):(3*N/2));
else
for X=0:M-1
for Y=0:N-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
g(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
end
g=g./sqrt(sum(sum(g.*g)));
image_reconstruct=image_reconstruct+proj*g;
image_r=double(image_r)-proj*g;
n;
end
X=imread('lena128.bmp');
%image=X(1:128,1:128);
%I1=mat2gray(image);
%imshow(I1);
%imshow(X);
%figure;
I2=mat2gray(image_reconstruct);
photo(65:128,1:64)=I2;
%%%循环3%%%
X=imread('lena128.bmp');
image=X(1:64,65:128);
[M,N]=size(image);
K_thmin=0;
%K_thmax=max(M,N)-1;
K_thmax=179;
K_umin=0;
K_umax=M;
K_vmin=0;
K_vmax=N;
K_sxmin=0;
K_sxmax=round(log2(M));
K_symin=0;
K_symax=round(log2(N));
image_reconstruct=zeros(M,N);
image_r=image;
%image_reconstruct=(1/(M*N))*sum(sum(image));
%image_r=image-image_reconstruct;
result=zeros(6,iterative_number);
for n=1:iterative_number
[proj,u_re,v_re,sx_re,sy_re,K_re]=GAS(image_r,M,N,K_thmin,K_thmax,K_umin,K_umax,K_vmin,K_vmax,K_sxmin,K_sxmax,K_symin,K_symax);
result(1,n)=proj;
result(2,n)=u_re;
result(3,n)=v_re;
result(4,n)=sx_re;
result(5,n)=sy_re;
result(6,n)=K_re;
if(sx_re<M/10&&sy_re<N/10)
sx_left=u_re-2*sx_re;
sy_left=v_re-2*sy_re;
sx_right=u_re+2*sx_re;
sy_right=v_re+2*sy_re;
if(sx_left<1)
sx_left=1;
end
if(sy_left<1)
sy_left=1;
end
if(sx_right>M)
sx_right=M;
end
if(sy_right>N)
sy_right=N;
end
g=zeros(M,N);
for X=sx_left-1:sx_right-1
for Y=sy_left-1:sy_right-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
g(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
elseif (sx_re>M/4&&sy_re>N/4)
sx_re=sx_re/2;
sy_re=sy_re/2;
for X=0:M-1
for Y=0:N-1
x=(X-u_re)/sx_re;
y=(Y-v_re)/sy_re;
XY=[cos(K_re) sin(K_re);-sin(K_re) cos(K_re)]*[x y]';
xx=XY(1);
yy=XY(2);
gr(X+1,Y+1)=(4*(xx^2)-2)*exp(-(xx^2+yy^2));
end
end
x=0:N-1;
y=0:M-1;
评论0