# How to rasterise a greyscale image using only black & white pixels?

I want to convert greyscale images to ones that have just black and white pixels.

Simply dividing the input pixels into black or white based on being below or above a set grey level, doesn't give nice results. I'm therefore looking for an algorithm that does some rasterisation.

My internet search led to many tutorials on how to rasterise using PhotoShop and similar applications, which is not what I'm after.

Would anyone be willing to point me to an online source that explains this kind of algorithms and/or explain a bit how to approach this problem?

• Here’s an old blog post I wrote about this topic, including code: crisluengo.net/archives/355 Oct 6, 2021 at 3:08
• @CrisLuengo Wow, thanks Chris. I've immediately added that to my short list of sources. Had a quick peek and your post looks great; will read over the weekend. Oct 6, 2021 at 6:43

The process of converting a grey scale image to 1-bit image of black and white pixels is called dithering. There are multiple different algorithms to achieve it with different looking results. Try the Wikipedia article on dither.

• Thanks for reminding me about dithering, a concept I'd encountered decades ago but forgot to connect the dots ;-) when thinking about this problem. I'll be using Floyd-Steinberg Dithering. Oct 6, 2021 at 6:38
• Just to be clear that the term "dithering" is a bit of a misnomer with the Floyd-Steinberg thing. That is error diffusion a.k.a. noise-shaped quantization, but it is not dithered. true dithering requires a random number generated noise that is added to the greyscale value before it is quantized to black or white. Noise shaping can be used with dithered quantization or undithered quantization. Oct 7, 2021 at 1:54

Such a conversion reduces the quantization of information with perceptual care, and is sometimes called dithering (as answered be @justme) or halftoning. It may play jointly on pixel value or spatial location, as illustrated below :

"Halftoning or analog halftoning is a process that simulates shades of gray by varying the size of tiny black dots arranged in a regular pattern"

In the above link, halftoning might encompass other techniques, like patterning, value dithering, spatial dithering, error diffusion. Ordered or averaged dithering are described in Image Dithering — How to Deceive your Eyes?

• Thanks for pointing out the broader context of problems like this! I've selected @Justme's answer because he was a bit earlier and is what I need. But of course your answer is very selectable too. Oct 6, 2021 at 6:40
• Perfect, and you reminded me to upvote @Justme's answer as well Oct 6, 2021 at 8:09