This commit is contained in:
Louis Heredero 2023-12-05 00:15:40 +01:00
parent 0657c28d7d
commit 979807f399
2 changed files with 13 additions and 0 deletions

View File

@ -99,6 +99,17 @@ object ImageFilters {
Math.max(0, Math.min(255, value + (Math.random()*2-1)*intensity)).toInt 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]] = { def mask(a: Array[Array[Color]], maskImg: Array[Array[Int]]): Array[Array[Color]] = {
val maskWidth: Int = maskImg.length val maskWidth: Int = maskImg.length
val maskHeight: Int = if (maskWidth == 0) 0 else maskImg(0).length val maskHeight: Int = if (maskWidth == 0) 0 else maskImg(0).length

View File

@ -55,5 +55,7 @@ object ImageProcessingApp extends App {
val imageFile: String = "./res/collins_eileen.png" val imageFile: String = "./res/collins_eileen.png"
val org = new ImageGraphics(imageFile, "Original", -768, -512) val org = new ImageGraphics(imageFile, "Original", -768, -512)
val sepia = new ImageGraphics(imageFile, "Sepia", -256, -512) val sepia = new ImageGraphics(imageFile, "Sepia", -256, -512)
val noise = new ImageGraphics(imageFile, "Noise", 256, -512)
sepia.setPixelsColor(ImageFilters.sepia(org.getPixelsColor())) sepia.setPixelsColor(ImageFilters.sepia(org.getPixelsColor()))
noise.setPixelsColor(ImageFilters.noise(org.getPixelsColor(), 50))
} }