hw/hw5/SeamCarver.java
private double energyY(int x, int y) {
        // x stands for column, y stands for row
        // energy along Y => row 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;
        x1 = x;
        x2 = x;

        if (y > 0 && y < height() - 1) {
            y1 = y - 1;
            y2 = y + 1;
        } else if (y == 0) {
            y1 = height() - 1;
            y2 = y + 1;
        } else if (y == height() - 1) {
            y1 = y - 1;
            y2 = 0;
        } else {
            throw new IllegalArgumentException("y is out of bounds!");
        }

        Color u = pic.get(x1, y1);
        Color d = pic.get(x2, y2);

        double Ry = Math.abs(u.getRed() - d.getRed());
        double Gy = Math.abs(u.getGreen() - d.getGreen());
        double By = Math.abs(u.getBlue() - d.getBlue());

        return Math.pow(Ry, 2) + Math.pow(Gy, 2) + Math.pow(By, 2);
    }
/**
     * private helper function
     *
     * compute energy along Y-direction
     *
     */
private helper function
compute energy along Y-direction
private helper function compute energy along Y - direction
private double energyY(int x, int y) {
        int x1, x2, y1, y2;
        x1 = x;
        x2 = x;
        if (y > 0 && y < height() - 1) {
            y1 = y - 1;
            y2 = y + 1;
        } else if (y == 0) {
            y1 = height() - 1;
            y2 = y + 1;
        } else if (y == height() - 1) {
            y1 = y - 1;
            y2 = 0;
        } else {
            throw new IllegalArgumentException("y is out of bounds!");
        }
        Color u = pic.get(x1, y1);
        Color d = pic.get(x2, y2);
        double Ry = Math.abs(u.getRed() - d.getRed());
        double Gy = Math.abs(u.getGreen() - d.getGreen());
        double By = Math.abs(u.getBlue() - d.getBlue());
        return Math.pow(Ry, 2) + Math.pow(Gy, 2) + Math.pow(By, 2);
    }
private double energyY ( int x , int y ) { int x1 , x2 , y1 , y2 ; x1 = x ; x2 = x ; if ( y > 0 && y < height ( ) - 1 ) { y1 = y - 1 ; y2 = y + 1 ; } else if ( y == 0 ) { y1 = height ( ) - 1 ; y2 = y + 1 ; } else if ( y == height ( ) - 1 ) { y1 = y - 1 ; y2 = 0 ; } else { throw new IllegalArgumentException ( "y is out of bounds!" ) ; } Color u = pic . get ( x1 , y1 ) ; Color d = pic . get ( x2 , y2 ) ; double Ry = Math . abs ( u . getRed ( ) - d . getRed ( ) ) ; double Gy = Math . abs ( u . getGreen ( ) - d . getGreen ( ) ) ; double By = Math . abs ( u . getBlue ( ) - d . getBlue ( ) ) ; return Math . pow ( Ry , 2 ) + Math . pow ( Gy , 2 ) + Math . pow ( By , 2 ) ; }
private helper function
 compute energy along Y-direction
private helper function compute energy along Y - direction
// x stands for column, y stands for row // energy along Y => row 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)