src/io/github/marwlod/seam_carving/SeamCarver.java
// energy of pixel at column x and row y
energy of pixel at column x and row y
energy of pixel at column x and row y
public double energy(int x, int y) {
        if (x < 0 || x > rgb.length - 1 || y < 0 || y > rgb[0].length - 1) throw new IllegalArgumentException("Points must be inside the picture");
        if (x == 0 || x == rgb.length - 1 || y == 0 || y == rgb[0].length - 1) return 1000;
        int rgbLowerX = rgb[x-1][y];
        int rgbHigherX = rgb[x+1][y];
        int rgbLowerY = rgb[x][y-1];
        int rgbHigherY = rgb[x][y+1];
        int squaredGradX = getSquaredGradient(rgbLowerX, rgbHigherX);
        int squaredGradY = getSquaredGradient(rgbLowerY, rgbHigherY);
        return Math.sqrt(squaredGradX + squaredGradY);
    }
public double energy ( int x , int y ) { if ( x < 0 || x > rgb . length - 1 || y < 0 || y > rgb [ 0 ] . length - 1 ) throw new IllegalArgumentException ( "Points must be inside the picture" ) ; if ( x == 0 || x == rgb . length - 1 || y == 0 || y == rgb [ 0 ] . length - 1 ) return 1000 ; int rgbLowerX = rgb [ x - 1 ] [ y ] ; int rgbHigherX = rgb [ x + 1 ] [ y ] ; int rgbLowerY = rgb [ x ] [ y - 1 ] ; int rgbHigherY = rgb [ x ] [ y + 1 ] ; int squaredGradX = getSquaredGradient ( rgbLowerX , rgbHigherX ) ; int squaredGradY = getSquaredGradient ( rgbLowerY , rgbHigherY ) ; return Math . sqrt ( squaredGradX + squaredGradY ) ; }
energy of pixel at column x and row y
energy of pixel at column x and row y
// all pixels at the perimeter has 1000 energy // all the others has energy calculated from neighboring pixels (right, left, up, down)