Tip
See the Examples section of the static properties for more examples.
public sealed class ErrorDiffusionDitherer : IDitherer
Public NotInheritable Class ErrorDiffusionDitherer
Implements IDitherer
public ref class ErrorDiffusionDitherer sealed : IDitherer
[<SealedAttribute>]
type ErrorDiffusionDitherer =
class
interface IDitherer
end
The constructor can be used to create an error diffusion ditherer using a custom matrix.
Use the static properties to obtain an instance with predefined parameters.
The ErrorDiffusionDitherer class uses an adaptive dithering technique, which disperses the quantization error of each pixels to the neighboring ones. Thereby the strength of the dithering is automatically adjusted by the algorithm itself, which provides good results also for palettes with uneven color distribution (which is not the case for ordered dithering, for example).
As the dithered result of a pixel depends on the already processed pixels, the ErrorDiffusionDitherer does not support parallel processing, which makes it slower than most of the other dithering methods.
The following table demonstrates the effect of the dithering:
Original image | Quantized image |
---|---|
|
|
|
|
Calculation of the quantization error may happen in two ways. The publicly available algorithms usually calculate the error for each color channels, which usually provides good results with color palettes. However, when quantizing color images with a black and white or grayscale palette, this approach may fail. For example, if the quantizer returns black for a fully saturated blue pixel, the quantization error is zero on the red and green channels and 100% on the blue channel. The problem is that this error cannot be propagated to the neighboring pixels if they have the same color because adding any more blue to already fully saturated blue pixels will not change anything. Therefore, the ErrorDiffusionDitherer can propagate quantization error by brightness based on human perception, which is more appropriate for palettes with grayscale colors. The ErrorDiffusionDitherer tries to auto detect the strategy for each dithering session but this can be overridden by the ConfigureErrorDiffusionMode method.
The following table demonstrates the effect of different strategies:
Original image | Quantized image |
---|---|
|
|
|
|
A typical artifact of error diffusion dithering is a ripple effect, which often appears in homogeneous areas of the dithered image. This is due to the fact that most filters propagate quantization errors mostly to right and down, whereas pixels are processed left-to-right in each line while lines are scanned top-down (raster processing). The ripple effect can be reduced if every second line is processed in the opposite direction (serpentine processing). You can use the ConfigureProcessingDirection method to obtain an ErrorDiffusionDitherer with serpentine processing mode, which processes even lines left-to-right and odd lines right-to-left.
The following table demonstrates the effect of different processing directions:
Original image | Quantized image |
---|---|
|
|
ErrorDiffusionDitherer | Initializes a new instance of the ErrorDiffusionDitherer class using the specified matrix, divisor and matrixFirstPixelIndex. |
Atkinson | Gets an ErrorDiffusionDitherer instance using the filter used by the Apple programmer Bill Atkinson. Uses a 4x3 matrix of only 6 effective values, and propagates only the 75% of the quantization error, which may cause total loss of details of light and dark areas (result may seem under- or overexposed) whereas midtones have higher contrast and preserve details better. |
Burkes | Gets an ErrorDiffusionDitherer instance using the filter proposed by D. Burkes in 1988. Uses a 5x2 matrix, which is actually the same as the first two lines of the matrix used by the Stucki filter. |
FloydSteinberg | Gets an ErrorDiffusionDitherer instance using the original filter proposed by Floyd and Steinberg in 1975 when they came out with the idea of error diffusion dithering. Uses a small, 3x2 matrix so the processing is somewhat faster than by the other alternatives. |
JarvisJudiceNinke | Gets an ErrorDiffusionDitherer instance using the filter proposed by Jarvis, Judice and Ninke in 1976. Uses a 5x3 matrix so the processing is slower than by the original Floyd-Steinberg filter but distributes errors in a wider range. |
Sierra2 | Gets an ErrorDiffusionDitherer instance using the two-line filter proposed by Frankie Sierra in 1990. Uses a 5x2 matrix so this somewhat faster than the three-line version and still provides a similar quality. |
Sierra3 | Gets an ErrorDiffusionDitherer instance using the three-line filter proposed by Frankie Sierra in 1989. Uses a 5x3 matrix so this is the slowest Sierra filter but this disperses errors to the furthest among them. |
SierraLite | Gets an ErrorDiffusionDitherer instance using a small two-line filter proposed by Frankie Sierra. Uses a 3x2 matrix so it has the same performance as the Floyd-Steinberg algorithm and also produces a quite similar result. |
StevensonArce | Gets an ErrorDiffusionDitherer instance using the hexagonal filter proposed by Stevenson and Arce in 1985. Uses a fairly large, 7x4 matrix, but due to the hexagonal arrangement of the coefficients the processing performance is comparable to a rectangular 5x3 matrix. |
Stucki | Gets an ErrorDiffusionDitherer instance using the filter proposed by P. Stucki in 1981. Uses a 5x3 matrix so the processing is slower than by the original Floyd-Steinberg filter but distributes errors in a wider range. |
ConfigureErrorDiffusionMode | Gets a new ErrorDiffusionDitherer instance that has the specified error diffusion mode. |
ConfigureProcessingDirection | Gets a new ErrorDiffusionDitherer instance that has the specified processing direction. |
InitializeAsync |
Gets an IDitheringSession instance potentially asynchronously that can be used to dither the result of the specified IQuantizingSession
applied to the specified source.
If ditherer is a known ditherer that can be evaluated quickly, then this method might be executed synchronously.
This method is available in.NET Framework 4.0 and above. (Defined by DithererExtensions) |