Skip to content

Commit

Permalink
Merge pull request #3 from julyskies/develop
Browse files Browse the repository at this point in the history
Updates for Laplasian & Sobel filters
  • Loading branch information
peterdee authored Feb 3, 2023
2 parents 5169081 + add2b1a commit d730b95
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 8 additions & 11 deletions processing/laplasian-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ 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 {
width, height := len(source), len(source[0])
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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions processing/sobel-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
}
Expand Down

0 comments on commit d730b95

Please sign in to comment.