dither

package module
v0.0.0-...-b1743f5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: MIT Imports: 2 Imported by: 0

README

go-haftone

This repository contains a implemenation of dithering algorithm written in go.

Dithering is the reprographic technique that use error diffusion to create the illusion of color depth in images on systems with a limited color palette (see more here)

usage

Type go run cmd/dither.go --help to check the option supported.

Usage:
go run <image>
Options:
  -filters string
    	name of the filters to apply, options: 'floydSteinberg', 'burkes', 'sierra', 'sierra2', 'sierra3', 'stucki', 'atkinson' (default floydSteinberg)
  -multiplier float
    	Error multiplier (default 1.18)
  -outputdir string
			Directory name, where to save the generated images (default "output")
example

The library implements the following dithering methods: floydSteinberg, burkes, sierra, sierra2, stucki, atkinson and support monochrome and color image

Filter Input Output
floydSteinberg
burkes
sierra
sierra2
stucki
atkinson

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Atkinson = NewFilter(
	"atkinson",
	[][]float32{
		{0.0, 0.0, 1.0 / 8.0, 1.0 / 8.0},
		{1.0 / 8.0, 1.0 / 8.0, 1.0 / 8.0, 0.0},
		{0.0, 1.0 / 8.0, 0.0, 0.0},
	},
)
View Source
var Burkes = NewFilter(
	"burkes",
	[][]float32{
		{0.0, 0.0, 0.0, 8.0 / 32.0, 4.0 / 32.0},
		{2.0 / 32.0, 4.0 / 32.0, 8.0 / 32.0, 4.0 / 32.0, 2.0 / 32.0},
		{0.0, 0.0, 0.0, 0.0, 0.0},
	},
)
View Source
var FloydSteinberg = NewFilter(
	"floydSteinberg",
	[][]float32{
		[]float32{0.0, 0.0, 0.0, 7.0 / 48.0, 5.0 / 48.0},
		[]float32{3.0 / 48.0, 5.0 / 48.0, 7.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0},
		[]float32{1.0 / 48.0, 3.0 / 48.0, 5.0 / 48.0, 3.0 / 48.0, 1.0 / 48.0},
	},
)
View Source
var Sierra2 = NewFilter(
	"sierra2",
	[][]float32{
		{0.0, 0.0, 0.0, 4.0 / 16.0, 3.0 / 16.0},
		{1.0 / 16.0, 2.0 / 16.0, 3.0 / 16.0, 2.0 / 16.0, 1.0 / 16.0},
		{0.0, 0.0, 0.0, 0.0, 0.0},
	},
)
View Source
var Sierra3 = NewFilter(
	"sierra3",
	[][]float32{
		{0.0, 0.0, 0.0, 5.0 / 32.0, 3.0 / 32.0},
		{2.0 / 32.0, 4.0 / 32.0, 5.0 / 32.0, 4.0 / 32.0, 2.0 / 32.0},
		{0.0, 2.0 / 32.0, 3.0 / 32.0, 2.0 / 32.0, 0.0},
	},
)
View Source
var SierraLite = NewFilter(
	"sirra",
	[][]float32{
		{0.0, 0.0, 2.0 / 4.0},
		{1.0 / 4.0, 1.0 / 4.0, 0.0},
		{0.0, 0.0, 0.0},
	},
)
View Source
var Stucki = NewFilter(
	"stucki",
	[][]float32{
		{0.0, 0.0, 0.0, 8.0 / 42.0, 4.0 / 42.0},
		{2.0 / 42.0, 4.0 / 42.0, 8.0 / 42.0, 4.0 / 42.0, 2.0 / 42.0},
		{1.0 / 42.0, 2.0 / 42.0, 4.0 / 42.0, 2.0 / 42.0, 1.0 / 42.0},
	},
)

Functions

func Color

func Color(original image.Image, filter Filter, errorMultiplier float32) image.Image

func Grayscale

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

func Monochrome

func Monochrome(original image.Image, filter Filter, errorMultiplier float32) image.Image

func Threshold

func Threshold(img *image.Gray, th uint8) *image.Gray

Types

type Filter

type Filter struct {
	Name   string
	Matrix [][]float32
}

func NewFilter

func NewFilter(name string, matrix [][]float32) *Filter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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