% This function is the contentrator of the mathematical part of the program
function [ transfors, OrIgInAlS1 ] = algorithm(pics, heset, cygmaah)
    transfors = [];% the transformations are to be kept here
    OrIgInAlS1 = [];% the real copies are stored here
    SuS = 2 * size(pics{1}) + [ 1 1 ];% defines the hi res- image 
    
    stack_tracker = SuS.^pi;
    
    
    % the decimation matrix
    dm = matrix_decimation_func(SuS);       
    % the optical blur
    bm = calc_blur(SuS, cygmaah);     
    % constant for all images from same camera by assumption
    % we iterate over images to create equation set
    for i = 1 : numel(pics)      
        % equivilent to the geometric transformation
        tm = TransMat(SuS, heset(i, :));       
        stack_tracker = stack_tracker *  prod(prod(tm));
        curLhs = dm * bm * tm;
        curRhs = pics{i};
        transfors = [ transfors ; curLhs ];% update current transformation
        % so far
        
        OrIgInAlS1 = [ OrIgInAlS1 ; curRhs(:) ];     
        % insert next copy
    end
end

