Such values should ideally be clipped by the find_closest_palette_color() function, rather than clipping the intermediate values, since a subsequent error may bring the value back into range. The pseudocode can result in pixel values exceeding the valid values (such as greater than 255 in 8-bit greyscale images). 8-bit greyscale to 1-bit black-and-white), find_closest_palette_color() may perform just a simple rounding, for example:įind_closest_palette_color(oldpixel) = round(oldpixel / 255) When converting greyscale pixel values from a high to a low bit depth (e.g. Newpixel := find_closest_palette_color(oldpixel) įor each y from top to bottom do for each x from left to right do This works for any approximately linear encoding of pixel values, such as 8-bit integers, 16-bit integers or real numbers in the range. The algorithm described above is in the following pseudocode. In some implementations, the horizontal direction of scan alternates between lines this is called "serpentine scanning" or boustrophedon transform dithering. For optimal dithering, the counting of quantization errors should be in sufficient accuracy to prevent rounding errors from affecting the result. For example, 50% grey data could be dithered as a black-and-white checkerboard pattern. The diffusion coefficients have the property that if the original pixel values are exactly halfway in between the nearest available colors, the dithered result is a checkerboard pattern. Hence, if a number of pixels have been rounded downwards, it becomes more likely that the next pixel is rounded upwards, such that on average, the quantization error is close to zero. Each time, the quantization error is transferred to the neighboring pixels, while not affecting the pixels that already have been quantized. The algorithm scans the image from left to right, top to bottom, quantizing pixel values one by one. The pixel indicated with a star (*) indicates the pixel currently being scanned, and the blank pixels are the previously-scanned pixels.
0 Comments
Leave a Reply. |