frames = 5;
vid = videoinput('winvideo',1);
set(vid.source,'AnalogVideoFormat','pal_i');
triggerconfig(vid, 'immediate');
foto = getsnapshot(vid);
foto = uint16(foto);
res = size(foto); 
whos;
res(1)
res(2)
res(3)
for i=1:res(2)
    for j=1:res(1)
        for n=2:frames
            temp = getsnapshot(vid);
            temp = uint16(temp);
            foto(i,j,:)=foto(i,j,:)+temp(i,j,:);
        end
        foto(i,j,:)=foto(i,j,:)/frames;
    end
end
foto = uint8(foto);
image(foto(:,:,:,1))