From 25f69fceb87f72beedf73620a476a2a86d2cef02 Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 1 Feb 2023 21:30:14 +0300 Subject: [PATCH 1/2] Fix Sobel filter color encoding --- processing/sobel-filter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/processing/sobel-filter.go b/processing/sobel-filter.go index f22c8b3..8811a25 100644 --- a/processing/sobel-filter.go +++ b/processing/sobel-filter.go @@ -39,9 +39,9 @@ func SobelFilter(source [][]color.Color) [][]color.Color { gradientY += int(grayColor) * sobelVertical[i][j] } } - colorCode := 255 - uint8(int(math.Sqrt( - float64((gradientX*gradientX)+(gradientY*gradientY)), - ))) + colorCode := 255 - uint8(utilities.MaxMin(math.Sqrt( + float64(gradientX*gradientX+gradientY*gradientY), + ), 255, 0)) destination[x][y] = color.RGBA{colorCode, colorCode, colorCode, 255} } } From add2b1a00f8a074a68fac6528e2246b4bb6fe347 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 3 Feb 2023 21:47:32 +0300 Subject: [PATCH 2/2] Update Laplacian kernel, fix color calculation --- processing/laplasian-filter.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/processing/laplasian-filter.go b/processing/laplasian-filter.go index 7535429..007ea15 100644 --- a/processing/laplasian-filter.go +++ b/processing/laplasian-filter.go @@ -2,16 +2,15 @@ package processing import ( "image/color" - "math" "github.com/julyskies/brille/constants" "github.com/julyskies/brille/utilities" ) -var laplasianKernel = [3][3]int{ - {0, -1, 0}, - {-1, 4, -1}, - {0, -1, 0}, +var laplacianKernel = [3][3]int{ + {-1, -1, -1}, + {-1, 8, -1}, + {-1, -1, -1}, } func LaplasianFilter(source [][]color.Color) [][]color.Color { @@ -19,7 +18,7 @@ func LaplasianFilter(source [][]color.Color) [][]color.Color { destination := utilities.CreateGrid(width, height) for x := 0; x < width; x += 1 { for y := 0; y < height; y += 1 { - gradientX := 0 + averageSum := 0 for i := 0; i < 3; i += 1 { for j := 0; j < 3; j += 1 { k := utilities.GradientPoint(x, i, width) @@ -28,13 +27,11 @@ func LaplasianFilter(source [][]color.Color) [][]color.Color { source[x+k][y+l], constants.GRAYSCALE_AVERAGE, ) - gradientX += int(grayColor) * laplasianKernel[i][j] + averageSum += int(grayColor) * laplacianKernel[i][j] } } - colorCode := 255 - uint8(int(math.Sqrt( - float64((gradientX * gradientX)), - ))) - destination[x][y] = color.RGBA{colorCode, colorCode, colorCode, 255} + channel := 255 - uint8(utilities.MaxMin(averageSum, 255, 0)) + destination[x][y] = color.RGBA{channel, channel, channel, 255} } } return destination