dither -- reduce number of colors in an image with dithering
dither [-dv] [-p name[.size]] input output
dither processes image files in PNG or binary PPM format with the goal of reducing its number of colors. Functionality includes generating a palette of colors automatically and writing the output image with the signal optionally dithered (Floyd-Steinberg method).
Arguments for the input and output file are both required.
The palette used in the operation can be generated from different presets and sizes, or be completely customized. Details about palette generation are described below in the corresponding section.
The input file format is deduced by analysing the image header. The output file format is decided according to its extension. Use a .png
extension to have output written as a PNG file. Any other extension will result in a binary PPM file.
Accepted options are:
- -v
-
Verbose mode: the program will write the palette used to
stdout
. Useful to capture a palette generated by the program. - -p name[.size]
-
Palette generation method. Size must be an integer greater than 0 and is optional in some cases. Check the section on palettes below to learn more.
- -d
-
Disables dithering. Final image will have pixels matched to the closest palette color only.
These are the possible palettes and their descriptions, according to the identifier. If no palette is set the program will use rgb by default.
- auto
-
Automatically generate a palette of colors from the input image, using a median-cut algorithm. Size is required and must be a power of 2.
- custom
-
Custom palette, given by the user and read from
stdin
. Size is required. The palette format must be a sequence of triplets, integers in the range [0-255] separated by whitespace. Example:0 0 0 12 150 255 255 255 255
- rgb
-
Standard 8 colors RGB, equivalent to 3-bit RGB. Size is not required and will be ignored if set.
- bw
-
Black and white palette. Size is optional and will default to 2. When size is greater than 2, a grayscale palette with size number of colors will be generated.
Apply dithering to an image, using a 3-bit RGB palette:
$ dither input.ppm output.ppm
Apply dithering to an image, using a 4 tone grayscale palette:
$ dither -p bw.4 input.ppm output.ppm
Apply dithering to an image, using an automatically generated palette of 8 colors, dumping the palette to a file named palette.txt:
$ dither -vp auto.8 input.ppm output.ppm > palette.txt
Only generate a palette of colors of size 16, printing it to stdout
without saving the final image:
$ dither -vp auto.16 input.ppm /dev/null
Thank you Robert W. Floyd, Louis Steinberg and Paul Heckbert for your work and development of these algorithms.
This software and manual were written by Cesar Tessarin on August 2017.