Package seamcarving
Class SeamCarver
- java.lang.Object
-
- seamcarving.SeamCarver
-
public class SeamCarver extends Object
Seam carving, an approach for content-aware image resizing. Given aPicture, anEnergyFunction, and aSeamFinderalgorithm,removeHorizontal()orremoveVertical()seams from the picture.- See Also:
Picture,EnergyFunction,SeamFinder
-
-
Field Summary
Fields Modifier and Type Field Description private EnergyFunctionfTheEnergyFunctionfor determining the minimum-cost seam.private static StringINPUT_PATHPath to the input image.private doublelastRemovedSeamEnergyThe energy for the last-removed seam, or NaN if no seam has been removed.private static StringOUTPUT_PATHPath to the output image.private PicturepictureThePicture.private SeamFinderseamFinderTheSeamFinderimplementation.
-
Constructor Summary
Constructors Constructor Description SeamCarver(File file, EnergyFunction f, SeamFinder seamFinder)Constructs a seam carver by reading thePicturefrom the file, using the givenEnergyFunctionandSeamFinderimplementations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublelastRemovedSeamEnergy()Returns the energy of the last-removed seam, or NaN if no seam has been removed yet.static voidmain(String[] args)private Picturepicture()Returns a copy of the current picture.List<Integer>removeHorizontal()Removes and returns a minimum-cost horizontal seam from the picture.List<Integer>removeVertical()Removes and returns a minimum-cost vertical seam from the picture.private static voidvalidate(Picture picture, List<Integer> seam)Checks that the seam is a valid horizontal seam in the picture.
-
-
-
Field Detail
-
INPUT_PATH
private static final String INPUT_PATH
Path to the input image.- See Also:
- Constant Field Values
-
OUTPUT_PATH
private static final String OUTPUT_PATH
Path to the output image.- See Also:
- Constant Field Values
-
f
private final EnergyFunction f
TheEnergyFunctionfor determining the minimum-cost seam.
-
seamFinder
private final SeamFinder seamFinder
TheSeamFinderimplementation.
-
lastRemovedSeamEnergy
private double lastRemovedSeamEnergy
The energy for the last-removed seam, or NaN if no seam has been removed.
-
-
Constructor Detail
-
SeamCarver
public SeamCarver(File file, EnergyFunction f, SeamFinder seamFinder) throws IOException
Constructs a seam carver by reading thePicturefrom the file, using the givenEnergyFunctionandSeamFinderimplementations.- Parameters:
file- the file path to the image.f- theEnergyFunction.seamFinder- theSeamFinder.- Throws:
IOException- if an error occurs during reading.
-
-
Method Detail
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
validate
private static void validate(Picture picture, List<Integer> seam)
Checks that the seam is a valid horizontal seam in the picture.- Parameters:
picture- the input picture.seam- the seam to remove.
-
picture
private Picture picture()
Returns a copy of the current picture.- Returns:
- a copy of the current picture.
-
removeHorizontal
public List<Integer> removeHorizontal()
Removes and returns a minimum-cost horizontal seam from the picture.- Returns:
- a minimum-cost horizontal seam.
-
removeVertical
public List<Integer> removeVertical()
Removes and returns a minimum-cost vertical seam from the picture.- Returns:
- a minimum-cost vertical seam.
-
lastRemovedSeamEnergy
public double lastRemovedSeamEnergy()
Returns the energy of the last-removed seam, or NaN if no seam has been removed yet.- Returns:
- the energy of the last-removed seam, or NaN if no seam has been removed yet.
-
-