private void removeSeam(int[] a) {
        width = width - 1;
        int[][] oldimg = img;
        img = new int[height][width];
        for (int y = 0; y < height; y++) {
            int p = a[y];
            System.arraycopy(oldimg[y], 0, img[y], 0, p);
            System.arraycopy(oldimg[y], p + 1, img[y], p, width - p);
        }
        double[][] oldenergy = energy;
        energy = new double[height][width];
        for (int y = 0; y < height; y++) {
            int p = a[y];
            System.arraycopy(oldenergy[y], 0, energy[y], 0, p);
            System.arraycopy(oldenergy[y], p + 1, energy[y], p, width - p);
            // not at left boundary
            if (p != 0) {
                energy[y][p - 1] = energy(p - 1, y);
            }
            // not at right boundary
            if (p < width) {
                energy[y][p] = energy(p, y);
            }
        }
    }