ppmdither
Dither PPM images for better color reduction
TLDR
Read a PPM image, apply dithering and save it to a file
Specify the desired number of shades for each primary color
Specify the dimensions of the dithering matrix
SYNOPSIS
ppmdither [-floyd | -fs | -atkinson | -diffusion | -median | -threshold num | -nofs] [-red | -green | -blue | -red mapfile | -green mapfile | -blue mapfile] [-gamma num] [-ncolors num] [-map mapfile] [-output filename] [--] [inputfile]
PARAMETERS
inputfile
The PPM image file to be dithered. If not specified, ppmdither reads from standard input.
-red
Dither the red component of the image. Can optionally be followed by a mapfile to define the colors for red component dithering.
-green
Dither the green component of the image. Can optionally be followed by a mapfile to define the colors for green component dithering.
-blue
Dither the blue component of the image. Can optionally be followed by a mapfile to define the colors for blue component dithering.
-floyd / -fs
Apply Floyd-Steinberg error diffusion dithering. -fs is a synonym for -floyd.
-atkinson
Use Atkinson dithering, which preserves more detail than Floyd-Steinberg but with less contrast.
-diffusion
Use a generic error diffusion dithering algorithm.
-median
Apply median-cut dithering, which is good for quantizing to a few colors.
-threshold num
Use a simple thresholding dithering algorithm. num is the threshold value (0-255). This is the default if no other algorithm is specified.
-nofs
Explicitly disable error diffusion, resulting in simple thresholding. This is equivalent to using -threshold without a specific num.
-gamma num
Apply gamma correction to the image before dithering. num specifies the gamma value.
-ncolors num
Quantize the image to num colors before dithering. This limits the output color palette.
-map mapfile
Use the colors present in mapfile (another PPM image) as the target color map for dithering.
-output filename
Write the dithered output image to filename instead of standard output.
--
Marks the end of command-line options, useful if inputfile starts with a hyphen.
DESCRIPTION
ppmdither is a command-line utility from the Netpbm suite designed to dither PPM (Portable Pixmap) images. Dithering is a technique used to approximate a continuous-tone image with a limited number of colors, often just a few, to simulate greater color depth. This is particularly useful for displays or printers that have a restricted color palette, or for creating artistic effects.
The command offers a variety of dithering algorithms, allowing users to choose the method best suited for their needs. By default, it employs a simple thresholding algorithm. However, more sophisticated options like Floyd-Steinberg, Atkinson, and generic error diffusion are available, which distribute quantization errors to adjacent pixels to improve image quality. It also supports quantizing to a specified number of colors or using a custom color map from another image. Input images are read from standard input by default, and the dithered output is written to standard output, making it suitable for piping with other Netpbm tools.
CAVEATS
Combining -red/-green/-blue and -map options, or using -gamma with color maps, can lead to non-obvious results, requiring experimentation. Additionally, the -threshold option may not function correctly when used in conjunction with certain color map-related options.
HISTORY
ppmdither is part of the Netpbm project, a comprehensive suite of graphics utilities and libraries for manipulating image files, primarily in the PNM (Portable Anymap) formats (PBM, PGM, PPM). It has been a standard tool within this suite for many years, providing essential dithering capabilities for various image processing workflows.