Documentation ¶
Overview ¶
Example ¶
package main import ( "image" "image/png" "os" "github.com/lestrrat-go/dither" ) func main() { f, err := os.Open("file.png") if err != nil { return } defer f.Close() img, _, err := image.Decode(f) if err != nil { return } ditheredImg := dither.Monochrome(dither.Burkes, img, 1.18) png.Encode(os.Stdout, ditheredImg) }
Output:
Index ¶
- Variables
- func Color(m Matrixer, input image.Image, errorMultiplier float32) image.Image
- func Grayscale(input image.Image) *image.Gray
- func Monochrome(m Matrixer, input image.Image, errorMultiplier float32) image.Image
- func Threshold(input *image.Gray) *image.Gray
- type Filter
- type Matrix
- type MatrixBuilder
- type Matrixer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Atkinson = NewFilter( "Atkinson", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 1.0 / 8.0, 1.0 / 8.0}). AddRow([]float32{1.0 / 8.0, 1.0 / 8.0, 1.0 / 8.0, 0.0}). AddRow([]float32{0.0, 1.0 / 8.0, 0.0, 0.0}). Build(), )
View Source
var Burkes = NewFilter( "Burkes", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 0.0, 8.0 / 32.0, 4.0 / 32.0}). AddRow([]float32{2.0 / 32.0, 4.0 / 32.0, 8.0 / 32.0, 4.0 / 32.0, 2.0 / 32.0}). AddRow([]float32{0.0, 0.0, 0.0, 0.0, 0.0}). Build(), )
View Source
var FloydSteinberg = NewFilter( "FloydSteinberg", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 0.0, 7.0 / 48.0, 5.0 / 48.0}). AddRow([]float32{3.0 / 48.0, 5.0 / 48.0, 7.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0}). AddRow([]float32{1.0 / 48.0, 3.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0, 1.0 / 48.0}). Build(), )
View Source
var Sierra2 = NewFilter( "Sierra-2", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 0.0, 4.0 / 16.0, 3.0 / 16.0}). AddRow([]float32{1.0 / 16.0, 2.0 / 16.0, 3.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0}). AddRow([]float32{0.0, 0.0, 0.0, 0.0, 0.0}). Build(), )
View Source
var Sierra3 = NewFilter( "Sierra-3", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 0.0, 5.0 / 32.0, 3.0 / 32.0}). AddRow([]float32{2.0 / 32.0, 4.0 / 32.0, 5.0 / 32.0, 4.0 / 32.0, 2.0 / 32.0}). AddRow([]float32{0.0, 2.0 / 32.0, 3.0 / 32.0, 2.0 / 32.0, 0.0}). Build(), )
View Source
var SierraLite = NewFilter( "Sierra-Lite", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 2.0 / 4.0}). AddRow([]float32{1.0 / 4.0, 1.0 / 4.0, 0.0}). AddRow([]float32{0.0, 0.0, 0.0}). Build(), )
View Source
var Stucki = NewFilter( "Stucki", NewMatrixBuilder(5, 3). AddRow([]float32{0.0, 0.0, 0.0, 8.0 / 42.0, 4.0 / 42.0}). AddRow([]float32{2.0 / 42.0, 4.0 / 42.0, 8.0 / 42.0, 4.0 / 42.0, 2.0 / 42.0}). AddRow([]float32{1.0 / 42.0, 2.0 / 42.0, 4.0 / 42.0, 2.0 / 42.0, 1.0 / 42.0}). Build(), )
Functions ¶
func Monochrome ¶
Types ¶
type MatrixBuilder ¶
type MatrixBuilder struct {
// contains filtered or unexported fields
}
func NewMatrixBuilder ¶
func NewMatrixBuilder(cols, rows int) *MatrixBuilder
func (*MatrixBuilder) AddRow ¶
func (b *MatrixBuilder) AddRow(v []float32) *MatrixBuilder
func (*MatrixBuilder) Build ¶
func (b *MatrixBuilder) Build() *Matrix
Click to show internal directories.
Click to hide internal directories.