Files
x/image/filter/sigmoid.go

22 lines
492 B
Go

package filter
import (
"image"
"image/color"
"math"
)
func Sigmoid(src *image.Gray, contrast, midpoint float64) *image.Gray {
b := src.Bounds()
out := image.NewGray(b)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
v := float64(src.GrayAt(x, y).Y) / 255.0
adj := 1.0 / (1.0 + math.Exp(contrast*(midpoint-v)))
out.SetGray(x, y, color.Gray{Y: uint8(adj * 255)})
}
}
return out
}