frames=10; % Noise-reduction parameter <200      default:5    HQ:10
if exist('vid', 'var')
    disp('Video device already initialized')
else
    vid = videoinput('winvideo',1);
            disp('Video initialization: 5 seconds warm-up')
            start(vid);
            pause(5); % perform warm-up
            stop(vid);
            delete(vid);
            clear vid;
        vid = videoinput('winvideo',1);     % Setup input device
    set(vid.source,'AnalogVideoFormat','pal_i');    % and its format
    set(vid,'FramesPerTrigger',frames);
end
start(vid);
wait(vid,10);
foto = getdata(vid);
whos;
%   delete(vid);    % REMEMBER TO DO THAT after data collecting
%   clear vid;
res = size(foto);   % Obtain physical resolution
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; % DON'T DO THAT when data analysis
foto = uint8(foto); % Back to image (for viewing only)
try
    imaqmontage(foto(:,:,:,1:2)); % Camera noise is now reduced.
catch
    imaqmontage(foto(:,:,:,1));
end