Skip to content

theMagicalKarp/dithering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dithering

This is a simple project to demonstrate Floyd–Steinberg dithering as code.

What

Floyd–Steinberg dithering is an image dithering algorithm first published in 1976 by Robert W. Floyd and Louis Steinberg. It is commonly used by image manipulation software, for example when an image is converted into GIF format that is restricted to a maximum of 256 colors.

Why

One common application of dithering is to more accurately display graphics containing a greater range of colors than the display hardware is capable of showing. For example, dithering might be used in order to display a photographic image containing millions of colors on video hardware that is only capable of showing 256 colors at a time. The 256 available colors would be used to generate a dithered approximation of the original image. Without dithering, the colors in the original image would be quantized to the closest available color, resulting in a displayed image that is a poor representation of the original.

How

The algorithm achieves dithering using error diffusion, meaning it pushes (adds) the residual quantization error of a pixel onto its neighboring pixels, to be dealt with later. It spreads the debt out according to the distribution (shown as a map of the neighboring pixels):

calculation

A version of this algorithm can be seen in pkg/dithering.go.

Requirements

Bulid

$ make build

Run

$ ./build/dither -h
$ ./build/dither --in foo.png --out bar.png
$ make examples

Test

$ make test
$ make lint # requires golangci-lint installed

Verify CI Locally

Install act on your machine. This runs GitHub workflows locally.

$ act push

Examples

Original Dithered
american_gothic american_gothic_dith
baby baby_dith
milkyway milkyway_dith
gopher gopher_dith
michelangelo michelangelo_dith
Factor Image
Original factor
1 factor_1
2 factor_2
3 factor_3
4 factor_4

About

Floyd–Steinberg dithering (in Go)

Resources

License

Stars

Watchers

Forks