Introduction: Color Resolution and Dithering

Color Resolution

Color resolution (also called color depth) refers to the number of possible colors in an image, as determined by the bits-per-pixel. If an image in your computer is loaded from a FAX scanner or received as a FAX transmission, it is a black-and-white (1-bit) image. If it is loaded from a color scanner or a JPEG file, it can have 16 million colors. If it is loaded from a GIF file, it is likely to have 256 colors. There are many possibilities, ranging from two colors to 16 million.

LEADTOOLS lets you manipulate an image and display it on any Windows-compatible device, regardless of the image's color resolution. Therefore, in most cases you can load, display, modify and save an image without ever changing its color resolution. Nevertheless, in some cases you may need to increase or decrease the color resolution. The following are some examples:

Dithering

Whenever an image's color depth is reduced to 8-bits per pixel or less, a dithering method may come into play. One alternative is to use a nearest-color match (no dithering), which means that the color of each pixel is changed to the palette color that most closely matches it. If the original image contains subtle color details, the result of a nearest-color match may have large blotches of color that are not very pleasing.

Dithering methods create the appearance of more subtle shades by mixing in pixels of different colors. This is similar to the way newspaper pictures produce the appearance of shades of gray, even though the only actual colors are only black and white.

To enable dithering, set the dithering method inside the RasterImage to the required value and then instruct RasterCodecs to use this value when saving the image. The following example will load a 24-bits per pixel image and save it as bitonal with and without dithering.

Control Dithering During Save

C#
private static void Test(RasterCodecs codecs, string coloredImageFileName) 
{ 
   // RasterCodecs.Options.Save.UseImageDitheringMethod is false by default 
             
   RasterImage image = codecs.Load(coloredImageFileName); 
   // Save it with no dithering options 
   codecs.Save(image, @"C:\NotDithered.tif", RasterImageFormat.CcittGroup4, 1); 
             
   // Change the image dithering method to FloydStein 
   image.DitheringMethod = RasterDitheringMethod.FloydStein; 
   // Use the image dithering method when saving 
   codecs.Options.Save.UseImageDitheringMethod = true; 
   // Save it again 
   codecs.Save(image, @"C:\Dithered.tif", RasterImageFormat.CcittGroup4, 1); 
             
   image.Dispose(); 
} 

Variations in Dithering Methods

Ordered Dithering

Ordered dithering and cluster dithering are the fastest methods. They are effective for reducing the number of colors to 256 colors or less. Ordered dithering is the default dithering method when painting to a display device that is 256 colors or less.

These methods take advantage of the fact that the colors in most palettes are ordered so that similar shades are next to each other in the palette. Pixels used in dithering are taken from these adjacent colors to achieve the nearest shade. They place pixels from shades near to the original color to achieve a smoothing effect. Ordered dithering avoids blotches of color by adding to or subtracting from the nearest-color value of each pixel to ensure that adjacent pixels do not have exactly the same color. However, If the colors in the palette are not ordered, the results may be poor.

Error Diffusion Dithering

All of the other dithering methods in LEADTOOLS use error-diffusion algorithms. In error diffusion, the error is the difference between the original pixel color and the nearest match, and the algorithm spreads pixel placement (performs diffusion) around this error. Error-diffusion dithering produces better quality images than other methods for photographic images, images that are not going to be compressed with CCITT or run-length encoding, and images with continuous tones (gradients). If you use a LEADTOOLS function to change the color resolution of a bitmap in memory, you can choose from several different error diffusion dithering methods.

Floyd-Steinberg is a high-quality, fast error-diffusion method. It is the default method that LEADTOOLS uses if you reduce the color resolution when loading or saving an image, or if you specify error diffusion as the dithering method when painting to a display device that is 256 colors or less.

All of the alternative error-diffusion methods are slower than Floyd-Steinberg, and the quality may or may not be better, depending on the original image, and depending on whether the resulting image is to be displayed or printed. Stevenson Arce dithering, the slowest of the alternatives, is most likely to produce a higher quality result.

Choosing a Method

All error-diffusion methods produce similar results, and both ordered and error-diffusion dither algorithms have advantages and disadvantages:

In order to achieve the desired results for an image, it is usually best to apply each dithering method to the original, and see which yields the most desirable result.

The following figures illustrate the effects of using a couple of different dithering methods on an image.

A JPEG file of the original image is shown in the following figure:

beforedither.jpg

A JPEG file of the image after ordered dithering has been applied is shown in the following figure:

ordereddither.jpg

A JPEG file of the image after error diffusion dithering (Floyd-Steinberg) has been applied is shown in the following figure:

floydsteinbergdither.jpg

ROMM BGR Color Encodings

A family of wide-primary output-referred extended color-gamut BGR color encoding called Reference Output Medium Metric (ROMM) BGR Color encodings are used by digital still picture imaging systems to manipulate, store, transmit, display and print digital images. Unlike sRGB color encoding, the range of colors is not limited to those colors that can be displayed on a CRT monitor, and unlike e-sRGB, these encodings do not use negative RGB colorimetry coordinates.

ROMM color order can be used only with 24- or 48-bit bitmaps and is supported by the CMP/JPEG/Exif JPEG/JTIF/TIFF CMP file formats. There are colors that can be represented in RGB, but not in ROMM. Conversely, there are colors that can be represented in ROMM that cannot be represented in RGB. If you convert from one to the other you lose the colors that can be represented only in one of the colorspaces.

References

Introduction to Image Processing With LEADTOOLS

Dithering Methods

Codecs.CodecsThumbnailOptions.DitheringMethod property

ImageProcessing.ColorResolutionCommand.DitheringMethod property

RasterDitheringMethod enumeration

RasterDefaults.DitheringMethod property

RasterImage.DitheringMethod property

RasterImage.DitherLine method

RasterImage.StartDithering method

RasterImage.StopDithering method

RasterBufferConverter.Convert

Help Version 23.0.2024.3.4
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.