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