Halfgone Save

:white_square_button: Black and white digital halftoning

Project README

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")

original

Grayscale

gray := ImageToGray(img)

grayscale

Inverted grayscale

InvertGray(gray)

reversed_grayscale

Threshold dithering

halfgone.ThresholdDitherer{Threshold: 127}.Apply(gray)

threshold_dithering

Random threshold dithering

halfgone.RandomThresholdDitherer{MaxThreshold: 255, RNG: rng}.Apply(gray)

random_threshold_dithering

Importance sampling

halfgone.ImportanceSampling{N: 4000, Threshold: 100, RNG: rng}.Apply(gray)

importance_sampling

Bosch and Herman’s grid-based dithering

halfgone.GridDitherer{K: 5, Alpha: 3, Beta: 8, RNG: rng}.Apply(gray)

grid_dithering

Ordered dithering

Order-2 ordered dithering

halfgone.Order2OrderedDitherer{}.Apply(gray)

order_2_ordered_dithering

Order-3 ordered dithering

halfgone.Order3OrderedDitherer{}.Apply(gray)

order_3_ordered_dithering

Order-4 ordered dithering

halfgone.Order4OrderedDitherer{}.Apply(gray)

order_4_ordered_dithering

Order-8 ordered dithering

halfgone.Order8OrderedDitherer{}.Apply(gray)

order_8_ordered_dithering

Error-diffusion dithering

Floyd-Steinberg dithering

halfgone.FloydSteinbergDitherer{}.apply(gray)

floyd_steinberg_dithering

Jarvis-Judice-Ninke dithering

halfgone.JarvisJudiceNinkeDitherer{}.Apply(gray)

jarvis_judice_ninke_dithering

Stucki dithering

halfgone.StuckiDitherer{}.Apply(gray)

stucki_dithering

Atkinson dithering

halfgone.AtkinsonDitherer{}.Apply(gray)

atkinson_dithering

Burkes dithering

halfgone.BurkesDitherer{}.Apply(gray)

burkes_dithering

Sierra dithering

halfgone.SierraDitherer{}.Apply(gray)

seria_dithering

Two-row Sierra dithering

halfgone.TwoRowSierraDitherer{}.Apply(gray)

two_row_seria_dithering

Sierra Lite dithering

halfgone.SierraLiteDitherer{}.Apply(gray)

seria_lite_dithering

License

The MIT License (MIT). Please see the license file for more information.

Open Source Agenda is not affiliated with "Halfgone" Project. README Source: MaxHalford/halfgone
Stars
47
Open Issues
0
Last Commit
6 years ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating