function [finalTracks] = dotQuant(imageMatrix, maskXY, maskZ, maxLinkingDistance, maxGap, minimumTrackLength, pixelSize, stepSize, maxNoOfParticles, threshold)

meanIntensity = mean(imageMatrix(:));
threshold = meanIntensity*(threshold/100);
    binaryMaximaImage = findMaxima( imageMatrix, maskXY, maskZ, threshold, maxNoOfParticles ); 
    %finds cells that have higher values then a specified number of neighbors
    dataSize = size(imageMatrix);
    [Y, X, Z, t] = ind2sub(dataSize,find(binaryMaximaImage == 1));
    %converts index to subscripted coordinates. 
    %Matlab's default is to keep all coordinates as vector indices.
    %This converts them to subscripted coordinates: (Y,X,Z,t)
    %This is done this iteratively to all points in the image that 
    %...are local maximum
maximaCoordinates = [Y, X, Z, t]; 
%concentrates coordinates into a single 2D matrix   

timePoints = max(t);
%finds number of time points in data set
[frequentValue, frequency] = mode(t);
linksSize = max(frequency(:));
%finds max number of connectible particles in all time points
links = repmat(-1, timePoints, linksSize);
%creates a matrix that saves the links between two particles
coordinateSaver = repmat(-1, [frequency, 3, timePoints]);
%creates a matrix that saves maximum coordinates for each time point

for i = 1:timePoints-1
 [ timePoint1Matrix, timePoint2Matrix ] =...
     timeSplitter( maximaCoordinates, i, i+1 );
 
 timePoint1Elements = numel(timePoint1Matrix);
 timePoint2Elements = numel(timePoint2Matrix);
 coordinateSaver(1:(timePoint1Elements/3), :, i) = timePoint1Matrix;
 coordinateSaver(1:(timePoint2Elements/3), :, i+1) = timePoint2Matrix;
 %At every loop iteration the two metrices are cleared. Here they are 
 %saved in the coordinates saving metrix that was declared outside the loop. 
 %The number of coordinates is third the number of elements as each 
 %coordinate has three values.
 
 target_indices = hungarianlinker(timePoint1Matrix, timePoint2Matrix, maxLinkingDistance, pixelSize, stepSize);
 %The hungarian algorithm receives two metrices with connectible
 %coordinates and a max linking distance value. It uses these inputs to
 %find the global minima for particle connections. The output is specified
 %in the algorithm itself.
 
 targetElements = numel(target_indices);
 links(i, 1:targetElements) = target_indices;
 %At every iteration the target_indices metrix is cleared. Here it is saved 
 %in the links saving metrix that was declared outside the loop.
 
end

tracks  = linksToTracks( coordinateSaver, links );
%This function receives the coordinates matrix and the links matrix and
%creates a matrix of tracks from the two.

finalTracks = gapCloser( tracks, maxGap, maxLinkingDistance, pixelSize, stepSize, minimumTrackLength );

end

