private void transpose() {
        double[][] energyt = new double[width][height];
        int[][] imgt = new int[width][height];
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                energyt[x][y] = energy[y][x];
                imgt[x][y] = img[y][x];
            }
        }
        energy = energyt;
        img = imgt;
        energyt = null;
        imgt = null;
        int tmp = width;
        width = height;
        height = tmp;
    }