Skip to main content

Dithering

Version: 2.0

Dithering

Dithering is a technique used in computer graphics to reduce the visual side effects of color quantization. A quantized image may contain flat areas and patches of color that may significantly affect the quality of the quantized image. Dithering creates an illusion of more color and more detail by a certain kind of mixing of available colors. Factors such as quality of the original image, dithering algorithm, dithering percentage and color palette can affect the resulting quality of the dithered image.

Guidelines for selecting Dithering Algorithms​

DynamicPDF Rasterizer supports two dithering algorithms, Floyd-Steinberg algorithm and Bayer algorithm.

Floyd-Steinberg algorithm : Floyd-Steinberg is a high-quality, error-diffusion method. It is the default dithering algorithm DynamicPDF Rasterizer uses during the creation of indexed images. This method can be used for creating both monochrome images and color images. Floyd-Steinberg algorithm gives good-quality images compared to Bayer algorithm, but is slower than Bayer algorithm.

Bayer algorithm : Bayer algorithm is an Ordered dithering algorithm. Bayer algorithm can be used for creating both monochrome images and color images. Bayer algorithm is faster than Floyd-Steinberg algorithm, but image quality may be lower.

Guidelines for selecting Dithering Percentage​

DynamicPDF Rasterizer allows the Dithering percentage to be set (from 0 to 100) which specifies the percentage of pixels that will undergo dithering.

Zero percentage dithering means no pixels are dithered and the resulting image may contain bands and patches. A higher dithering percentage creates an illusion of more color and more detail, but increases the file size. Low dithering percentages can be applied if file size is more important than the quality of the image. Images with primarily solid colors (Example: A PDF e-book�s pages converted to image) may work well with low dithering percentage. Images with gradients and more number of colors (ordinary images) may require high dithering percentages to prevent color banding. A high dithering percentage slightly affects performance also.

The below example illustrates rasterizing a PDF document into an indexed PNG using the Floyd-Steinberg dithering algorithm at a dithering percentage of 100:

PdfRasterizer rasterizer = new PdfRasterizer("C:\\DocumentA.pdf");
AutoPalette autoPalette = new AutoPalette(QuantizationAlgorithm.Octree, 256);
PngIndexedColorFormat pngIndexedColorFormat = new PngIndexedColorFormat(autoPalette, 100, DitheringAlgorithm.FloydSteinberg);
PngImageFormat png = new PngImageFormat(pngIndexedColorFormat);
rasterizer.Draw("C:\\DocumentA_Dithered_Page.png", png, ImageSize.Dpi72);
Dim rasterizer As New PdfRasterizer("C:\DocumentA.pdf")
Dim autoPalette As New AutoPalette(QuantizationAlgorithm.Octree, 256)
Dim pngIndexedColorFormat As New PngIndexedColorFormat(autoPalette, 100, DitheringAlgorithm.FloydSteinberg)
Dim png As New PngImageFormat(pngIndexedColorFormat)
rasterizer.Draw("C:\DocumentA_Dithered_Page.png", png, ImageSize.Dpi72)