This commit is contained in:
Louis Heredero 2023-12-04 17:24:25 +01:00
parent 54fa312113
commit ddd8952e9a
2 changed files with 12 additions and 0 deletions

View File

@ -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
}
})
}

View File

@ -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()))
}