# Color image to black and white image

This online calculator converts color images to black and white images. Two options are possible: luminosity threshold or Floyd–Steinberg dithering.

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

Threshold: 127
Source image
• Drag files here
Source image

Black and white image

### 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.

1. 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
$Y = 0.2126R + 0.7152G + 0.0722B$

2. 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].

#### Floyd–Steinberg dithering

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:

${\displaystyle {\begin{bmatrix}&&*&{\frac {\displaystyle 7}{\displaystyle 16}}&\ldots \\\ldots &{\frac {\displaystyle 3}{\displaystyle 16}}&{\frac {\displaystyle 5}{\displaystyle 16}}&{\frac {\displaystyle 1}{\displaystyle 16}}&\ldots \\\end{bmatrix}}}$

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.

#### Jarvis dithering

${\begin{bmatrix}&&&*&{\frac {7}{48}}&{\frac {5}{48}}&\ldots \\ \ldots &{\frac {3}{48}}&{\frac {5}{48}}&{\frac {7}{48}}&{\frac {5}{48}}&{\frac {3}{48}}&\ldots\\ \ldots &{\frac {1}{48}}&{\frac {3}{48}}&{\frac {5}{48}}&{\frac {3}{48}}&{\frac {1}{48}}&\ldots \\\end{bmatrix}}$

#### Stucki dithering

${\begin{bmatrix}&&&*&{\frac {8}{42}}&{\frac {4}{42}}&\ldots \\ \ldots &{\frac {2}{42}}&{\frac {4}{42}}&{\frac {8}{42}}&{\frac {4}{42}}&{\frac {2}{42}}&\ldots\\ \ldots &{\frac {1}{42}}&{\frac {2}{42}}&{\frac {4}{42}}&{\frac {2}{42}}&{\frac {1}{42}}&\ldots \\\end{bmatrix}}$

1. R.W. Floyd, L. Steinberg, An adaptive algorithm for spatial grey scale. Proceedings of the Society of Information Display 17, 75–77 (1976).

URL copiado para a área de transferência