function [ energy ] = calcEnergy( data )
%calcEnergy Calculate the energy of the given data

%[height width colors] = size(data);

energy = [];

%fprintf('Calculating energy...\n');
%tic

%{

pct = 0;
lastPct = 0;
pctStep = 5;

for x = 1 : width
    for y = 1 : height
        for c = 1 : colors
            n = 0;
            d1 = 0;
            d2 = 0;
            d3 = 0;
            d4 = 0;
            if x > 1
                d1 = abs(data(x - 1, y, c) - data(x,y,c));
                n = n + 1;
            end
            if x < width
                d2 = abs(data(x + 1, y, c) - data(x,y,c));
                n = n + 1;
            end
            if y > 1
                d3 = abs(data(x, y - 1, c) - data(x,y,c));
                n = n + 1;
            end
            if y < height
                d4 = abs(data(x, y + 1, c) - data(x,y,c));
                n = n + 1;
            end
            res(c) = (d1 + d2 + d3 + d4) / n;
        end
        avg = mean(res(1:colors));
        energy(x,y) = avg;
    end
    pct = (x / width) * 100;
    if (floor(pct) - lastPct) >= pctStep
        lastPct = floor(pct);
        fprintf('\t%i%%\n', lastPct);
    end
end
%}

timeScaleFactor = 100.0;

imgr = im2double(data(:,:,1));
imgg = im2double(data(:,:,2));
imgb = im2double(data(:,:,3));

[txr tyr] = gradient(imgr);
[txg tyg] = gradient(imgg);
[txb tyb] = gradient(imgb);

txr = timeScaleFactor * abs(txr);
tyr = abs(tyr);

txg = timeScaleFactor * abs(txg);
tyg = abs(tyg);

txb = timeScaleFactor * abs(txb);
tyb = abs(tyb);

energy = (txr + txg + txb + tyr + tyg + tyb);



%toc

%fprintf('finished!\n');

