%
% Optical Imaging and Spectroscopy
%
% David J. Brady
% Duke University
% www.opticalimaging.org
%
% code used to generate figures 2.31, 2.32 and 2.33
%
%
% This script is run after tijMURA to produce an image 
%
%
%
noiseFactor=10;
signalNoise=0; %1 for noise, 0 for no signal noise
imagey=zeros(p);
for i=1:p;
    for j=1:p
        if abs((i-p/2)^2+(j-p/2)^2-200)<20
            imagey(i,j)=1;
        elseif abs((i-p/2)^2+(j-p/2)^2-75)<10 & i<25
            imagey(i,j)=1;
        end
    end
end
imagey(35,25)=1;
imagey(35,35)=1;
imagey(28:30,30)=1;
% Step 1 generate projected pattern
g=circConv(imagey,t);
% The following line adds signal dependent noise
g=g+signalNoise*(2*(rand(p)-0.5)).*sqrt(g);
% The following line adds signal independent noise
g=g+noiseFactor*rand(p);
figure(1);
clf;
set(gcf,'color','white');
subplot(2,2,1);
surf(g);
colormap('gray');
title('Measured data');
shading interp;
light('Position',[-2,2,5]);
lighting phong;
subplot(2,2,2);
fe=circConv(ht,g);
imagesc(fe);
axis square;
colormap('gray');
title('Reconstructed image');
subplot(2,2,3);
surf(fe);
colormap('gray');
title('Surface plot of reconstructed image');
axis tight;
shading interp;
light('Position',[-2,2,5]);
lighting phong;
subplot(2,2,4);
axis off;
str=[num2str(noiseFactor) '% additive noise'];
%str=['Uniformly distributed shot noise'];
%str=['no noise'];
text(0,0,str);
str=['Image reconstruction with a 59'];
text(0,.5,str);
str=['element MURA coded aperture'];
text(0,.4,str);


            