diff options
Diffstat (limited to 'Algorithms/Part-II/2-SeamCarving/PrintSeams.java')
| -rw-r--r-- | Algorithms/Part-II/2-SeamCarving/PrintSeams.java | 85 | 
1 files changed, 85 insertions, 0 deletions
diff --git a/Algorithms/Part-II/2-SeamCarving/PrintSeams.java b/Algorithms/Part-II/2-SeamCarving/PrintSeams.java new file mode 100644 index 0000000..2611d48 --- /dev/null +++ b/Algorithms/Part-II/2-SeamCarving/PrintSeams.java @@ -0,0 +1,85 @@ +/************************************************************************* + *  Compilation:  javac PrintSeams.java + *  Execution:    java PrintSeams input.png + *  Dependencies: SeamCarver.java SCUtility.java Picture.java StdDraw.java + * + * + *  Read image from file specified as command line argument. Print energy + *  of each image, as well as both seams, and the total energy of each seam. + * + *************************************************************************/ + +public class PrintSeams { + +    private static void printHorizontalSeam(SeamCarver sc) +    { +        double totalSeamEnergy = 0; + +        int[] horizontalSeam = sc.findHorizontalSeam(); +        for (int j = 0; j < sc.height(); j++) +        { +            for (int i = 0; i < sc.width(); i++) +            { +                char lMarker = ' '; +                char rMarker = ' '; +                if (j == horizontalSeam[i]) +                { +                    lMarker = '['; +                    rMarker = ']'; +                    totalSeamEnergy += sc.energy(i, j); +                } + +                System.out.printf("%c%6.0f%c ", lMarker, sc.energy(i, j), rMarker); +            } +            System.out.println(); +        } + +        System.out.printf("\nTotal energy: %.0f\n\n", totalSeamEnergy); +    } + + +    private static void printVerticalSeam(SeamCarver sc) +    { +        double totalSeamEnergy = 0; + +        int[] verticalSeam = sc.findVerticalSeam(); +        for (int j = 0; j < sc.height(); j++) +        { +            for (int i = 0; i < sc.width(); i++) +            { +                char lMarker = ' '; +                char rMarker = ' '; +                if (i == verticalSeam[j]) +                { +                    lMarker = '['; +                    rMarker = ']'; +                    totalSeamEnergy += sc.energy(i, j); +                } + +                System.out.printf("%c%6.0f%c ", lMarker, sc.energy(i, j), rMarker); +            } + +            System.out.println(); +        } + +        System.out.printf("\nTotal energy: %.0f\n\n", totalSeamEnergy); +    } + +    public static void main(String[] args) +    { +        Picture inputImg = new Picture(args[0]); +        System.out.printf("image is %d columns by %d rows\n", +                          inputImg.width(), inputImg.height()); +        //inputImg.show(); +        SeamCarver sc = new SeamCarver(inputImg); + +        System.out.printf("Displaying horizontal seam calculated.\n"); +        printHorizontalSeam(sc); + +        System.out.printf("Displaying vertical seam calculated.\n"); +        printVerticalSeam(sc); + + +    } + +}  | 
