Skip to content

Commit

Permalink
Update Laplacian kernel, fix color calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdee committed Feb 3, 2023
1 parent 2be1500 commit add2b1a
Showing 1 changed file with 8 additions and 11 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

0 comments on commit add2b1a

Please sign in to comment.