private int[] findSeam() {
        distTo = new double[height][width];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if (y == 0) {
                    // initialize the first row
                    distTo[y][x] = energy[y][x];
                } else {
                    distTo[y][x] = Double.POSITIVE_INFINITY;
                }
            }
        }
        pixelTo = new int[height][width];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                relax(x, y);
            }
        }
        return findPath();
    }