frames=50; %Noise-reduction parameter <200      default:5    HQ:10
    vid = videoinput('winvideo',1);     % Setup input device
    set(vid.source,'AnalogVideoFormat','pal_i');    % and its format
    set(vid,'FramesPerTrigger',frames);
start(vid);
% isrunning(vid) % Testing purposes...
wait(vid,5);
% isrunning(vid)
foto = getdata(vid);
    delete(vid);
    clear vid;
res = size(foto);   % Obtain physical resolution
% imaqmontage(foto);
foto = uint16(foto); % Arithm.main: uint8 overflow prevention in for loop 
whos;
for n=2:frames
foto(:,:,:,1)=foto(:,:,:,1)+foto(:,:,:,n);
end
foto(:,:,:,1)=foto(:,:,:,1)/frames;
foto = uint8(foto); % Back to image (for viewing only)
try
imaqmontage(foto(:,:,:,1:2)); % Camera noise is now reducted.
catch
imaqmontage(foto(:,:,:,1));
end