% Archana Gupta
% Project

%  clear all variables
clear all;

opengl neverselect;
%load first image to initailise imdat and imstack
imdat=load('wall000.m');
imstack=cat(3,imdat);

%load all the images and store in a stack
for i=1:16
    tem=sprintf('%1d',i);
    filename=['wall00' tem '.m'];
    imdat=load(filename);
    imstack=cat(3,imstack,imdat);
end

%find mean of all 17 image 
avgim =mean(imstack,3);
avgim1=avgim';

filtim=medfilt2(avgim1,[9 9]);

%reduce dimensions
filtim1 = im2col(filtim,[9 9]);
filtim2 = median(filtim1);
filtim3= col2im(filtim2,[1 1],size(avgim1)-8);
figure;
imagesc(filtim3);

%calling function cloud3d to covert to real world coordinates 
%and draw 3d cloud of points
[newpic,face]=cloud3d(filtim3);

%draw mesh
figure;
h = patch('faces',face,'vertices',newpic,'FaceColor',[0.2 1 0.5],'BackFaceLighting','lit');
view(3);
light('Position',[0.81 -0.04 0.59],'Style','infinite');


disp('done');







