This commit is contained in:
Louis Heredero 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
}
})
}

View File

@ -4,7 +4,7 @@ import isc.graphics.ImageGraphics
object ImageProcessingApp extends App {
val imageFile = "./res/collins_eileen.png"
/*val imageFile = "./res/collins_eileen.png"
val org = new ImageGraphics(imageFile, "Original", -500, -250)
val dest = new ImageGraphics(imageFile, "Duplicate", 0, -250)
val thresh = new ImageGraphics(imageFile, "Threshold", -500, 250)
@ -22,5 +22,19 @@ object ImageProcessingApp extends App {
mean2.setPixelsBW(ImageFilters.mean(mean2.getPixelsBW(), 4))
val edges = new ImageGraphics("./res/rice.jpg", "Edges", 500, 250)
edges.setPixelsBW(ImageFilters.edges(edges.getPixelsBW()))
edges.setPixelsBW(ImageFilters.edges(edges.getPixelsBW()))*/
val imageFile: String = "./res/grace_hopper.jpg"
val org = new ImageGraphics(imageFile, "Original", -768, -512)
val bw = new ImageGraphics(imageFile, "Black & White", -256, -512)
val threshold = new ImageGraphics(imageFile, "Threshold", 256, -512)
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)
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))
}