#super rozliseni pro plosny objekt

clear all
close all

L=7;
N=256;
delta=L/N;
[x,y]=meshgrid((-N/2:N/2-1)*delta);
r=sqrt((x).^2+(y).^2);
r1=sqrt((x-0.25).^2+(y+0.25).^2);
r2=sqrt((x+0.25).^2+(y+0.25).^2);
r3=sqrt((x).^2+(y-0.25).^2);
[fx,fy]=meshgrid((-N/2:N/2-1)/(N*delta));
rho=sqrt(fx.^2+fy.^2);
max(max(fx))


rectxy=(abs(x)<1.38).*(abs(y)<1);
#rectxy=r<0.6;
rectf=rho<2.9;
maskaf=1-rectf;
#imshow(rect,[])

#trueimg=(r1<0.2)+(r2<0.2)+(r3<0.2);#+(r4<0.08);
trueimg=(1+cos(20*x)).*rectxy;
max(max(trueimg))
figure(1)
imshow(trueimg,[])
print -dpng '-S640' 'trueimg.png'


truespect=fftshift(fft2(ifftshift(trueimg)));
figure(2)
imshow(abs(truespect),[0,max(max(abs(truespect)))/4])
print -dpng '-S640' 'truespect.png'



dataspect=truespect.*rectf;

figure(3)
imshow(abs(dataspect),[0,max(max(abs(dataspect)))/4]);
print -dpng '-S640' 'dataspect.png'




figure(4)
img=fftshift(ifft2(ifftshift(dataspect)));
imshow(abs(img),[])
print -dpng '-S640' 'image.png'


spect=dataspect;

for loop=1:5000

if(mod(loop,10)==0) loop endif

img=fftshift(ifft2(ifftshift(spect)));
#plot(x,abs(img))
img=img.*(img>0);
img=img.*rectxy;
#plot(x,abs(img))

spect=fftshift(fft2(ifftshift(img)));
spect=maskaf.*spect+rectf.*dataspect;




endfor

figure(5)
imshow(abs(img),[])
print -dpng '-S640' 'recimage.png'



figure(6)
imshow(abs(spect),[0,max(max(abs(spect)))/4]);
print -dpng '-S640' 'recspect.png'



#figure(7)
#imshow(abs(img).^2,[])



