This repository contains implementations of digital halftoning - also called dithering - algorithms written in Go. The implementations are restricted to black and white rendering and are based on the image
library from Go's standard library.
The implementations are quite fast but are not optimized for production where you would typically want to use bit shifting when possible. I moved the common code for error-diffusion dithering into a separate functions because it's always the same underlying algorithm, whether it be Floyd-Steinberg dithering or Stucki dithering. I did the same for ordered dithering. In production you would probably want to choose a particular dithering algorithm and avoid using generic code which makes it harder to write optimized code.
If you are interested in digital halftoning, this web page is, in my opinion, a fantastic introduction. I've also written a blog post which goes through some of the implementations.
img := LoadImage("images/penguin.jpg")
gray := ImageToGray(img)
InvertGray(gray)
halfgone.ThresholdDitherer{Threshold: 127}.Apply(gray)
halfgone.RandomThresholdDitherer{MaxThreshold: 255, RNG: rng}.Apply(gray)
halfgone.ImportanceSampling{N: 4000, Threshold: 100, RNG: rng}.Apply(gray)
halfgone.GridDitherer{K: 5, Alpha: 3, Beta: 8, RNG: rng}.Apply(gray)
halfgone.Order2OrderedDitherer{}.Apply(gray)
halfgone.Order3OrderedDitherer{}.Apply(gray)
halfgone.Order4OrderedDitherer{}.Apply(gray)
halfgone.Order8OrderedDitherer{}.Apply(gray)
halfgone.FloydSteinbergDitherer{}.apply(gray)
halfgone.JarvisJudiceNinkeDitherer{}.Apply(gray)
halfgone.StuckiDitherer{}.Apply(gray)
halfgone.AtkinsonDitherer{}.Apply(gray)
halfgone.BurkesDitherer{}.Apply(gray)
halfgone.SierraDitherer{}.Apply(gray)
halfgone.TwoRowSierraDitherer{}.Apply(gray)
halfgone.SierraLiteDitherer{}.Apply(gray)
The MIT License (MIT). Please see the license file for more information.