-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathShowSeams.java
46 lines (37 loc) · 1.59 KB
/
ShowSeams.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/******************************************************************************
* Compilation: javac ShowSeams.java
* Execution: java ShowSeams input.png
* Dependencies: SeamCarver.java SCUtility.java
*
* Read image from file specified as command-line argument. Show 3 images
* original image as well as horizontal and vertical seams of that image.
*
* % java ShowSeams HJoceanSmall.png
*
******************************************************************************/
import edu.princeton.cs.algs4.Picture;
import edu.princeton.cs.algs4.StdOut;
public class ShowSeams {
private static void showHorizontalSeam(SeamCarver sc) {
Picture ep = SCUtility.toEnergyPicture(sc);
int[] horizontalSeam = sc.findHorizontalSeam();
Picture epOverlay = SCUtility.seamOverlay(ep, true, horizontalSeam);
epOverlay.show();
}
private static void showVerticalSeam(SeamCarver sc) {
Picture ep = SCUtility.toEnergyPicture(sc);
int[] verticalSeam = sc.findVerticalSeam();
Picture epOverlay = SCUtility.seamOverlay(ep, false, verticalSeam);
epOverlay.show();
}
public static void main(String[] args) {
Picture picture = new Picture(args[0]);
StdOut.printf("%d-by-%d image\n", picture.width(), picture.height());
picture.show();
SeamCarver sc = new SeamCarver(picture);
StdOut.printf("Displaying horizontal seam calculated.\n");
showHorizontalSeam(sc);
StdOut.printf("Displaying vertical seam calculated.\n");
showVerticalSeam(sc);
}
}