@@ -8,6 +8,12 @@ import Pipelines.{EdgeDetection, MedianDenoiser, GibbsEdgeDetection, Pipeline}
88import Algorithms .Denoiser
99import Pipelines .GibbsDenoiser
1010
11+ /**
12+ * Main entry point
13+ *
14+ * sbt assembly
15+ * spark-submit --driver-memory 8g --master local[*] ./jar/binary.jar ./data/nike_noisy.png
16+ */
1117object Main {
1218
1319 var inputPathImage = " ./data/input.png"
@@ -48,6 +54,7 @@ object Main {
4854 println(s " Sub matrix size: ${subHeight}" )
4955 println(s " Paddding: ${padding}" )
5056
57+ // Get image as matrix
5158 val inputStream = FileUtils .getInputStream(inputPathImage)
5259 val inputImage = new Image ()
5360 val pixelArray = inputImage.getPixelMatrix(inputStream, true )
@@ -56,6 +63,7 @@ object Main {
5663
5764 // Define the Spark Job
5865 val job = new SparkJob (padding, subHeight, subWidth, denoiserRuns, debug)
66+ // Match the selected pipeline
5967 val pipeline = inputPiepeline match {
6068 case " GibbsDenoise" => new GibbsDenoiser (denoiserRuns)
6169 case " GibbsEdgeDetection" => new GibbsEdgeDetection (denoiserRuns)
@@ -64,16 +72,19 @@ object Main {
6472 }
6573
6674 println(" \n Start" )
75+ // Runs job and gets execution time
6776 val result = Utils .time(job.run(pixelMatrix, pipeline))
6877 if (debug > 0 )
6978 println(s " Time: ${result._2} ms " )
7079
80+ // Saves output image as file
7181 val outputStream = FileUtils .getOutputStream(outputPathImage)
7282 val outputImage = new Image ()
7383 outputImage.setPixelMatrix(result._1.data.map(_.toInt), result._1.rows, result._1.cols, true )
7484 outputImage.saveImage(outputStream)
7585 outputStream.close()
7686
87+ // Forges the output report
7788 val json = s """ {
7889 "time": ${result._2},
7990 "inputPiepeline": " ${inputPiepeline}",
@@ -86,11 +97,9 @@ object Main {
8697 "subWidth": ${subWidth}
8798 } """
8899
100+ // Saves report to file
89101 val jsonOutputStream = FileUtils .getOutputStream(outputPathJson)
90102 jsonOutputStream.write(json.getBytes(Charset .forName(" UTF-8" )))
91103 jsonOutputStream.close()
92104 }
93- }
94-
95- // sbt assembly
96- // spark-submit --driver-memory 8g --master local[*] ./jar/binary.jar ./data/nike_noisy.png
105+ }
0 commit comments