The calculator below converts the uploaded color image to a black and white image. Not a grayscale image as in Color to Grayscale Conversion, but an image consisting only of black and white dots. Four conversion methods are supported - using a luminance threshold value (which can be changed), Floyd-Steinberg dithering, Jarvis dithering, and Stucki dithering. You can read more about the calculator's algorithms below.
Color image to black and white image conversion
Using a luminosity threshold
The algorithm for this method of creating a black and white image is quite simple.
Calculate the luminosity (brightness) of a pixel. The calculator uses the standard coefficients (again, see Color to Grayscale Conversion) and the luminosity value is calculated as
- If the calculated value is higher than the threshold, replace the original pixel color with white. If lower or equal, replace the original pixel color with black.
By default, the calculator uses the value of 127 as a threshold, the middle of the range [0 ... 255].
Using only the threshold value results in too sharp transitions between black and white, especially at smooth edges. To overcome this problem, in 1976, Floyd and Steinberg proposed a dithering algorithm based on diffusion of the image quantization error. 1 The idea of the algorithm is to calculate quantization error (rounding error) and "return" part of it to the original image, distributing it between neighboring pixels that have yet to be processed.
In the Floyd-Steinberg algorithm, the error between adjacent pixels is distributed as follows:
As you can see, this distribution allows you to process the image in one pass - from left to right, top to bottom.
The pseudo-code of the algorithm from wikipedia:
for each y from top to bottom do for each x from left to right do oldpixel := pixel[x][y] newpixel := find_closest_palette_color(oldpixel) pixel[x][y] := newpixel quant_error := oldpixel - newpixel pixel[x + 1][y ] := pixel[x + 1][y ] + quant_error × 7 / 16 pixel[x - 1][y + 1] := pixel[x - 1][y + 1] + quant_error × 3 / 16 pixel[x ][y + 1] := pixel[x ][y + 1] + quant_error × 5 / 16 pixel[x + 1][y + 1] := pixel[x + 1][y + 1] + quant_error × 1 / 16
There are other dithering methods: Jarvis dithering, Stucki dithering, Burkes dithering, Sierra dithering, but they differ mostly in error diffusion scheme. I've included a couple of them. If you want any others, let me know in the comments.
R.W. Floyd, L. Steinberg, An adaptive algorithm for spatial grey scale. Proceedings of the Society of Information Display 17, 75–77 (1976). ↩