hw/hw5/SeamCarver.java
private double energyX(int x, int y) {
        // x stands for column, y stands for row
        // energy along X => column matters

        // a 3-by-4 image (x, y) W by H
        // (0, 0)  	  (1, 0)  	  (2, 0)
        // (0, 1)  	  (1, 1)  	  (2, 1)
        // (0, 2)  	  (1, 2)  	  (2, 2)
        // (0, 3)  	  (1, 3)  	  (2, 3)

        int x1, x2, y1, y2;
        y1 = y;
        y2 = y;


        // pixels in center
        if (x > 0 && x < width() - 1) {
            x1 = x - 1;
            x2 = x + 1;
        } else if (x == 0) {
            x1 = width() - 1;
            x2 = x + 1;
        } else if (x == width() - 1) {
            x1 = x - 1;
            x2 = 0;
        } else {
            throw new IllegalArgumentException("x is out of bounds!");
        }

        Color l = pic.get(x1, y1);
        Color r = pic.get(x2, y2);

        double Rx = Math.abs(l.getRed() - r.getRed());
        double Gx = Math.abs(l.getGreen() - r.getGreen());
        double Bx = Math.abs(l.getBlue() - r.getBlue());

        return Math.pow(Rx, 2) + Math.pow(Gx, 2) + Math.pow(Bx, 2);
    }
/**
     * private helper function
     *
     * compute energy along X-direction
     *
     */
private helper function
compute energy along X-direction
private helper function compute energy along X - direction
private double energyX(int x, int y) {
        int x1, x2, y1, y2;
        y1 = y;
        y2 = y;
        if (x > 0 && x < width() - 1) {
            x1 = x - 1;
            x2 = x + 1;
        } else if (x == 0) {
            x1 = width() - 1;
            x2 = x + 1;
        } else if (x == width() - 1) {
            x1 = x - 1;
            x2 = 0;
        } else {
            throw new IllegalArgumentException("x is out of bounds!");
        }
        Color l = pic.get(x1, y1);
        Color r = pic.get(x2, y2);
        double Rx = Math.abs(l.getRed() - r.getRed());
        double Gx = Math.abs(l.getGreen() - r.getGreen());
        double Bx = Math.abs(l.getBlue() - r.getBlue());
        return Math.pow(Rx, 2) + Math.pow(Gx, 2) + Math.pow(Bx, 2);
    }
private double energyX ( int x , int y ) { int x1 , x2 , y1 , y2 ; y1 = y ; y2 = y ; if ( x > 0 && x < width ( ) - 1 ) { x1 = x - 1 ; x2 = x + 1 ; } else if ( x == 0 ) { x1 = width ( ) - 1 ; x2 = x + 1 ; } else if ( x == width ( ) - 1 ) { x1 = x - 1 ; x2 = 0 ; } else { throw new IllegalArgumentException ( "x is out of bounds!" ) ; } Color l = pic . get ( x1 , y1 ) ; Color r = pic . get ( x2 , y2 ) ; double Rx = Math . abs ( l . getRed ( ) - r . getRed ( ) ) ; double Gx = Math . abs ( l . getGreen ( ) - r . getGreen ( ) ) ; double Bx = Math . abs ( l . getBlue ( ) - r . getBlue ( ) ) ; return Math . pow ( Rx , 2 ) + Math . pow ( Gx , 2 ) + Math . pow ( Bx , 2 ) ; }
private helper function
 compute energy along X-direction
private helper function compute energy along X - direction
// x stands for column, y stands for row // energy along X => column matters // a 3-by-4 image (x, y) W by H // (0, 0)  	  (1, 0)  	  (2, 0) // (0, 1)  	  (1, 1)  	  (2, 1) // (0, 2)  	  (1, 2)  	  (2, 2) // (0, 3)  	  (1, 3)  	  (2, 3) // pixels in center