This commit is contained in:
2023-12-04 19:26:22 +01:00
parent ddd8952e9a
commit 0a7a647126
2 changed files with 25 additions and 2 deletions

View File

@@ -59,4 +59,13 @@ object ImageFilters {
Math.sqrt(dx*dx + dy*dy).toInt
}
})
def sobel(a: Array[Array[Int]], intensityFactor: Double): 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-1)(x+1) + 2*a(y)(x+1) + a(y+1)(x+1) - a(y-1)(x-1) - 2*a(y)(x-1) - a(y+1)(x-1)
val dy: Int = a(y+1)(x-1) + 2*a(y+1)(x) + a(y+1)(x+1) - a(y-1)(x-1) - 2*a(y-1)(x) - a(y-1)(x+1)
(Math.sqrt(dx*dx + dy*dy)*intensityFactor).toInt
}
})
}