Package seamcarving.energy
Class DualGradientEnergyFunction
- java.lang.Object
-
- seamcarving.energy.DualGradientEnergyFunction
-
- All Implemented Interfaces:
EnergyFunction
public class DualGradientEnergyFunction extends Object implements EnergyFunction
Dual-gradient implementation of theEnergyFunctioninterface forPictureobjects.- See Also:
EnergyFunction,Picture
-
-
Constructor Summary
Constructors Constructor Description DualGradientEnergyFunction()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleapply(Picture picture, int x, int y)Returns the energy of pixel (x, y) in the given picture.private static intblue(int rgb)Returns the 8-bit blue color component as anint.private static doublecentralDiff(int rgb1, int rgb2)Returns the central difference between the two pixels' colors.private static doubleforwardDiff(int rgb1, int rgb2, int rgb3)Returns the forward/backward difference for the three adjacent pixels' colors.private static intgreen(int rgb)Returns the 8-bit green color component as anint.private static doublehorizontalDerivative(Picture picture, int x, int y)Returns the horizontal derivative for the (x, y) pixel in the picture.private static intred(int rgb)Returns the 8-bit red color component as anint.private static doubleverticalDerivative(Picture picture, int x, int y)Returns the vertical derivative for the (x, y) pixel in the picture.
-
-
-
Method Detail
-
horizontalDerivative
private static double horizontalDerivative(Picture picture, int x, int y)
Returns the horizontal derivative for the (x, y) pixel in the picture.- Parameters:
picture- the input picture.x- the x-index into the picture.y- the y-index into the picture.- Returns:
- the horizontal derivative for the (x, y) pixel in the picture.
-
verticalDerivative
private static double verticalDerivative(Picture picture, int x, int y)
Returns the vertical derivative for the (x, y) pixel in the picture.- Parameters:
picture- the input picture.x- the x-index into the picture.y- the y-index into the picture.- Returns:
- the vertical derivative for the (x, y) pixel in the picture.
-
centralDiff
private static double centralDiff(int rgb1, int rgb2)Returns the central difference between the two pixels' colors.- Parameters:
rgb1- the first pixel's color.rgb2- the second pixel's color.- Returns:
- the central difference between the two pixels' colors.
-
forwardDiff
private static double forwardDiff(int rgb1, int rgb2, int rgb3)Returns the forward/backward difference for the three adjacent pixels' colors.- Parameters:
rgb1- the first adjacent pixel's color.rgb2- the second adjacent pixel's color.rgb3- the third adjacent pixel's color.- Returns:
- the forward/backward difference for the three adjacent pixels' colors.
-
red
private static int red(int rgb)
Returns the 8-bit red color component as anint.- Parameters:
rgb- 24-bit color represented as three 8-bit red-green-blue color components.- Returns:
- the 8-bit red color component as an
int.
-
green
private static int green(int rgb)
Returns the 8-bit green color component as anint.- Parameters:
rgb- 24-bit color represented as three 8-bit red-green-blue color components.- Returns:
- the 8-bit green color component as an
int.
-
blue
private static int blue(int rgb)
Returns the 8-bit blue color component as anint.- Parameters:
rgb- 24-bit color represented as three 8-bit red-green-blue color components.- Returns:
- the 8-bit blue color component as an
int.
-
apply
public double apply(Picture picture, int x, int y)
Description copied from interface:EnergyFunctionReturns the energy of pixel (x, y) in the given picture.- Specified by:
applyin interfaceEnergyFunction- Parameters:
picture- the input picture.x- the x-index into the picture.y- the y-index into the picture.- Returns:
- the energy of pixel (x, y) in the given picture.
-
-