% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
%
% Aliased filter images, figure 7.13
%
figure(1);set(gcf,'color','white');
xrange=linspace(-2,62,512);
yrange=linspace(-2,14,128);
%
% one wavelength is 4 samples
%
[x,y]=meshgrid(xrange,yrange);
imgD=(1+cos(2*pi*((x+2).^2/128+(y+2).^2/200)))/2;
fnumber=1;
h=jinc(sqrt((x-30).^2+(y-6).^2)/fnumber).^2;
h=h(33:98,225:288);
imgL=conv2(imgD,h,'same');
imgL=imgL/max(max(imgL));
% Effect of down sampling
%
% sampling at one half wavelength scale
%
noiseLevel=(0.05)^2;
dSr=kron(eye(256),[1 1 ])/2;
dSl=kron(eye(64),[1 1])/2;
dxrange=linspace(-2,62,256);
dyrange=linspace(-2,14,64);
imgLd1=dSl*imgL*dSr';
imgLd1=imnoise(imgLd1,'gaussian',0,noiseLevel);
subplot(3,1,1,'align');imagesc(dxrange(10:248),dyrange(5:60),imgLd1(5:60,10:248));colormap 'gray';
title('Critically sampled');axis image;
% subplot(6,1,2,'align');
% plot(dxrange(10:248),imgLd1(32,10:248));axis tight;
% sampling at one wavelength scale
%
dSr=kron(eye(128),[1 1 1 1])/4;
dSl=kron(eye(32),[1 1 1 1])/4;
dxrange=linspace(-2,62,128);
dyrange=linspace(-2,14,32);
imgLd1=dSl*imgL*dSr';
imgLd1=imnoise(imgLd1,'gaussian',0,noiseLevel);
subplot(3,1,2,'align');imagesc(dxrange(5:124),dyrange(3:30),imgLd1(3:30,5:124));colormap 'gray';
title('2x undersampled'); axis image;
% subplot(6,1,4,'align');
% plot(dxrange(5:124),imgLd1(16,5:124));axis tight;
% sampling at two wavelength scale
%
dSr=kron(eye(64),[1 1 1 1 1 1 1 1])/8;
dSl=kron(eye(16),[1 1 1 1 1 1 1 1])/8;
dxrange=linspace(-2,62,64);
dyrange=linspace(-2,14,16);
imgLd1=dSl*imgL*dSr';
imgLd1=imnoise(imgLd1,'gaussian',0,noiseLevel);
subplot(3,1,3,'align');imagesc(dxrange(3:62),dyrange(2:15),imgLd1(2:15,3:62));colormap 'gray';
title('4x undersampled '); axis image;xlabel('\lambda f/#');
% subplot(6,1,6,'align');
% plot(dxrange(3:62),imgLd1(8,3:62));axis tight;
% title('4x undersampled');xlabel('\lambda f/#');
hp=figure(1);
set(hp,'papersize',[6 9]);