diff --git a/src/imagefilters/ImageFilters.scala b/src/imagefilters/ImageFilters.scala index 7656a94..aa4ac71 100644 --- a/src/imagefilters/ImageFilters.scala +++ b/src/imagefilters/ImageFilters.scala @@ -50,4 +50,13 @@ object ImageFilters { } }) } + + def edges(a: Array[Array[Int]]): Array[Array[Int]] = filter(a, (value, x, y, width, height) => { + if (x == 0 || x == width - 1 || y == 0 || y == height - 1) value + else { + val dx: Int = a(y)(x+1) - a(y)(x-1) + val dy: Int = a(y+1)(x) - a(y-1)(x) + Math.sqrt(dx*dx + dy*dy).toInt + } + }) } diff --git a/src/imagefilters/ImageProcessingApp.scala b/src/imagefilters/ImageProcessingApp.scala index f01b05e..7568f3c 100644 --- a/src/imagefilters/ImageProcessingApp.scala +++ b/src/imagefilters/ImageProcessingApp.scala @@ -20,4 +20,7 @@ object ImageProcessingApp extends App { val mean2 = new ImageGraphics("./res/imageProcessing.jpg", "Mean 2", 250, 250) mean2.setPixelsBW(ImageFilters.mean(mean2.getPixelsBW(), 4)) + + val edges = new ImageGraphics("./res/rice.jpg", "Edges", 500, 250) + edges.setPixelsBW(ImageFilters.edges(edges.getPixelsBW())) }