From 0943bfa193d004299b1a3a9e539dc7f396d452b6 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 4 Dec 2023 21:32:30 +0100 Subject: [PATCH] task 7 --- src/imagefilters/ImageFilters.scala | 4 ++++ src/imagefilters/ImageProcessingApp.scala | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/imagefilters/ImageFilters.scala b/src/imagefilters/ImageFilters.scala index b3e0552..90c51d7 100644 --- a/src/imagefilters/ImageFilters.scala +++ b/src/imagefilters/ImageFilters.scala @@ -68,4 +68,8 @@ object ImageFilters { (Math.sqrt(dx*dx + dy*dy)*intensityFactor).toInt } }) + + def noise(a: Array[Array[Int]], intensity: Double): Array[Array[Int]] = filter(a, (value) => { + Math.max(0, Math.min(255, value + (Math.random()*2-1)*intensity)).toInt + }) } diff --git a/src/imagefilters/ImageProcessingApp.scala b/src/imagefilters/ImageProcessingApp.scala index 5e3eb0e..32faf8d 100644 --- a/src/imagefilters/ImageProcessingApp.scala +++ b/src/imagefilters/ImageProcessingApp.scala @@ -31,10 +31,12 @@ object ImageProcessingApp extends App { val blur = new ImageGraphics(imageFile, "Blurred", -768, 0) val edges = new ImageGraphics(imageFile, "Edge detection", -256, 0) val sobel = new ImageGraphics(imageFile, "Sobel", 256, 0) + val noise = new ImageGraphics(imageFile, "Noise", -768, 512) bw.setPixelsBW(ImageFilters.duplicate(org.getPixelsBW())) threshold.setPixelsBW(ImageFilters.threshold(org.getPixelsBW(), 128)) blur.setPixelsBW(ImageFilters.mean(org.getPixelsBW(), 3)) edges.setPixelsBW(ImageFilters.edges(org.getPixelsBW())) sobel.setPixelsBW(ImageFilters.sobel(org.getPixelsBW(), 0.3)) + noise.setPixelsBW(ImageFilters.noise(org.getPixelsBW(), 30)) }