Awesome
halfgone
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.
Original image
img := LoadImage("images/penguin.jpg")
Grayscale
gray := ImageToGray(img)
Inverted grayscale
InvertGray(gray)
Threshold dithering
halfgone.ThresholdDitherer{Threshold: 127}.Apply(gray)
Random threshold dithering
halfgone.RandomThresholdDitherer{MaxThreshold: 255, RNG: rng}.Apply(gray)
Importance sampling
halfgone.ImportanceSampling{N: 4000, Threshold: 100, RNG: rng}.Apply(gray)
Bosch and Herman’s grid-based dithering
halfgone.GridDitherer{K: 5, Alpha: 3, Beta: 8, RNG: rng}.Apply(gray)
Ordered dithering
Order-2 ordered dithering
halfgone.Order2OrderedDitherer{}.Apply(gray)
Order-3 ordered dithering
halfgone.Order3OrderedDitherer{}.Apply(gray)
Order-4 ordered dithering
halfgone.Order4OrderedDitherer{}.Apply(gray)
Order-8 ordered dithering
halfgone.Order8OrderedDitherer{}.Apply(gray)
Error-diffusion dithering
Floyd-Steinberg dithering
halfgone.FloydSteinbergDitherer{}.apply(gray)
Jarvis-Judice-Ninke dithering
halfgone.JarvisJudiceNinkeDitherer{}.Apply(gray)
Stucki dithering
halfgone.StuckiDitherer{}.Apply(gray)
Atkinson dithering
halfgone.AtkinsonDitherer{}.Apply(gray)
Burkes dithering
halfgone.BurkesDitherer{}.Apply(gray)
Sierra dithering
halfgone.SierraDitherer{}.Apply(gray)
Two-row Sierra dithering
halfgone.TwoRowSierraDitherer{}.Apply(gray)
Sierra Lite dithering
halfgone.SierraLiteDitherer{}.Apply(gray)
License
The MIT License (MIT). Please see the license file for more information.