function [ seam ] = findSeam( summedArea )
%findSeam Finds a seam of lowest energy from the given summed area table
%  A seam is basically an array of the length of the image, with indexes
%   for the height of the seam at each scanline.

seam = [];

[width height] = size(summedArea);

[v i] = min(summedArea(width,:));
seam(width) = i;

for x = (width - 1) : -1 : 1
    best = summedArea(x,i);
    nextI = i;
    if (i > 1)
        if (best > summedArea(x,i-1))
            best = summedArea(x,i-1);
            nextI = i-1;
        end
    end
    if (i < height)
        if (best > summedArea(x,i+1))
            best = summedArea(x,i+1);
            nextI = i+1;
        end
    end
    i = nextI;
    seam(x) = i;
end