dither

package module
v0.0.0-...-2a6e115 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2018 License: MIT Imports: 2 Imported by: 7

README

dither

Apply dithering to an arbitrary image

This is a fork of https://github.com/esimov/dithergo

SYNOPSIS

func Example() {
  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)
}

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

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 Color

func Color(m Matrixer, input image.Image, errorMultiplier float32) image.Image

func Grayscale

func Grayscale(input image.Image) *image.Gray

func Monochrome

func Monochrome(m Matrixer, input image.Image, errorMultiplier float32) image.Image

func Threshold

func Threshold(input *image.Gray) *image.Gray

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(name string, m *Matrix) *Filter

func (*Filter) Matrix

func (f *Filter) Matrix() *Matrix

func (*Filter) Name

func (f *Filter) Name() string

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

func NewMatrix

func NewMatrix(cols, rows int) *Matrix

func (*Matrix) Cols

func (m *Matrix) Cols() int

func (*Matrix) Get

func (m *Matrix) Get(x, y int) float32

func (*Matrix) Rows

func (m *Matrix) Rows() int

func (*Matrix) Set

func (m *Matrix) Set(x, y int, v float32)

func (*Matrix) SetRow

func (m *Matrix) SetRow(y int, v []float32) *Matrix

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

type Matrixer

type Matrixer interface {
	Matrix() *Matrix
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL