24 lines
538 B
Go
24 lines
538 B
Go
package filter
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
)
|
|
|
|
func Unsharp(src *image.Gray, radius int, amount float64) *image.Gray {
|
|
b := src.Bounds()
|
|
blur := BoxBlur(src, radius)
|
|
out := image.NewGray(b)
|
|
|
|
for y := b.Min.Y; y < b.Max.Y; y++ {
|
|
for x := b.Min.X; x < b.Max.X; x++ {
|
|
orig := float64(src.GrayAt(x, y).Y)
|
|
blr := float64(blur.GrayAt(x, y).Y)
|
|
out.SetGray(x, y, color.Gray{
|
|
Y: clamp(orig + amount*(orig-blr)),
|
|
})
|
|
}
|
|
}
|
|
return out
|
|
}
|