aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/Main.java
blob: 43571bb81bce52b89154c7c2b279ca483d23ebb6 (plain)
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
47
48
49
50
51
/**
 * @author Pacien TRAN-GIRARD
 * @author Timothée FLOURE
 */
public final class Main {

    public static void main(String[] args) {

        // Load image
        System.out.println("Load image...");
        int[][] image = Helper.read("doves.jpg");
        Helper.show(image, "Original");

        // Convert to grayscale
        System.out.println("Convert to grayscale...");
        float[][] gray = Color.toGray(image);
        Helper.show(Color.toRGB(gray), "Grayscale");

        // Smooth it
        System.out.println("Smooth image...");
        float[][] smooth = Filter.smooth(gray);
        Helper.show(Color.toRGB(smooth), "Smooth");

        // Apply Sobel
        System.out.println("Compute Sobel filter...");
        float[][] sobel = Filter.sobel(smooth);
        Helper.show(Color.toRGB(sobel), "Sobel");

        // Find best seam
        System.out.println("Find best seam...");
        int[] seam = Seam.find(sobel);
        Helper.show(Seam.merge(image, seam), "Best seam");

        // Shrink until it is a square
        int count = image[0].length - image.length;
        System.out.println("Shrink by removing " + count + " seams...");
        for (int i = 0; i < count; ++i) {
            sobel = Filter.sobel(Filter.smooth(Color.toGray(image)));
            seam = Seam.find(sobel);
            image = Seam.shrink(image, seam);
            System.out.println("Seam " + (i + 1) + "/" + count);
        }
        System.out.println("Done");
        Helper.show(image, "Shrink");

        // Save result
        Helper.write("doves.shrink.jpg", image);

    }

}