diff options
Diffstat (limited to 'src/main/java/Seam.java')
-rw-r--r-- | src/main/java/Seam.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/Seam.java b/src/main/java/Seam.java new file mode 100644 index 0000000..1cb4a0c --- /dev/null +++ b/src/main/java/Seam.java | |||
@@ -0,0 +1,75 @@ | |||
1 | /** | ||
2 | * @author Pacien TRAN-GIRARD | ||
3 | * @author Timothée FLOURE | ||
4 | */ | ||
5 | public final class Seam { | ||
6 | |||
7 | /** | ||
8 | * Compute shortest path between {@code from} and {@code to} | ||
9 | * | ||
10 | * @param successors adjacency list for all vertices | ||
11 | * @param costs weight for all vertices | ||
12 | * @param from first vertex | ||
13 | * @param to last vertex | ||
14 | * @return a sequence of vertices, or {@code null} if no path exists | ||
15 | */ | ||
16 | public static int[] path(int[][] successors, float[] costs, int from, int to) { | ||
17 | // TODO path | ||
18 | return null; | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * Find best seam | ||
23 | * | ||
24 | * @param energy weight for all pixels | ||
25 | * @return a sequence of x-coordinates (the y-coordinate is the index) | ||
26 | */ | ||
27 | public static int[] find(float[][] energy) { | ||
28 | // TODO find | ||
29 | return null; | ||
30 | } | ||
31 | |||
32 | /** | ||
33 | * Draw a seam on an image | ||
34 | * | ||
35 | * @param image original image | ||
36 | * @param seam a seam on this image | ||
37 | * @return a new image with the seam in blue | ||
38 | */ | ||
39 | public static int[][] merge(int[][] image, int[] seam) { | ||
40 | // Copy image | ||
41 | int width = image[0].length; | ||
42 | int height = image.length; | ||
43 | int[][] copy = new int[height][width]; | ||
44 | for (int row = 0; row < height; ++row) | ||
45 | for (int col = 0; col < width; ++col) | ||
46 | copy[row][col] = image[row][col]; | ||
47 | |||
48 | // Paint seam in blue | ||
49 | for (int row = 0; row < height; ++row) | ||
50 | copy[row][seam[row]] = 0x0000ff; | ||
51 | |||
52 | return copy; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Remove specified seam | ||
57 | * | ||
58 | * @param image original image | ||
59 | * @param seam a seam on this image | ||
60 | * @return the new image (width is decreased by 1) | ||
61 | */ | ||
62 | public static int[][] shrink(int[][] image, int[] seam) { | ||
63 | int width = image[0].length; | ||
64 | int height = image.length; | ||
65 | int[][] result = new int[height][width - 1]; | ||
66 | for (int row = 0; row < height; ++row) { | ||
67 | for (int col = 0; col < seam[row]; ++col) | ||
68 | result[row][col] = image[row][col]; | ||
69 | for (int col = seam[row] + 1; col < width; ++col) | ||
70 | result[row][col - 1] = image[row][col]; | ||
71 | } | ||
72 | return result; | ||
73 | } | ||
74 | |||
75 | } | ||