From 979807f399df26f5dd1b0f82bc3659d4974d9fb9 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 5 Dec 2023 00:15:40 +0100 Subject: [PATCH] task 8.4 --- src/imagefilters/ImageFilters.scala | 11 +++++++++++ src/imagefilters/ImageProcessingApp.scala | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/imagefilters/ImageFilters.scala b/src/imagefilters/ImageFilters.scala index 19818b7..ec66cb9 100644 --- a/src/imagefilters/ImageFilters.scala +++ b/src/imagefilters/ImageFilters.scala @@ -99,6 +99,17 @@ object ImageFilters { Math.max(0, Math.min(255, value + (Math.random()*2-1)*intensity)).toInt }) + def noise(a: Array[Array[Color]], intensity: Double): Array[Array[Color]] = colorFilter(a, (col) => { + val r: Double = col.getRed + (Math.random()*2-1)*intensity + val g: Double = col.getGreen + (Math.random()*2-1)*intensity + val b: Double = col.getBlue + (Math.random()*2-1)*intensity + new Color( + Math.max(0, Math.min(255, r)).toInt, + Math.max(0, Math.min(255, g)).toInt, + Math.max(0, Math.min(255, b)).toInt + ) + }) + def mask(a: Array[Array[Color]], maskImg: Array[Array[Int]]): Array[Array[Color]] = { val maskWidth: Int = maskImg.length val maskHeight: Int = if (maskWidth == 0) 0 else maskImg(0).length diff --git a/src/imagefilters/ImageProcessingApp.scala b/src/imagefilters/ImageProcessingApp.scala index f75cbb8..32977bc 100644 --- a/src/imagefilters/ImageProcessingApp.scala +++ b/src/imagefilters/ImageProcessingApp.scala @@ -55,5 +55,7 @@ object ImageProcessingApp extends App { val imageFile: String = "./res/collins_eileen.png" val org = new ImageGraphics(imageFile, "Original", -768, -512) val sepia = new ImageGraphics(imageFile, "Sepia", -256, -512) + val noise = new ImageGraphics(imageFile, "Noise", 256, -512) sepia.setPixelsColor(ImageFilters.sepia(org.getPixelsColor())) + noise.setPixelsColor(ImageFilters.noise(org.getPixelsColor(), 50)) }