# R is a cool image editor #2: Dithering algorithms

**Statistic on aiR**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here I implemented in R some dithering algorithms:

– **Floyd-Steinberg dithering**

– **Bill Atkinson dithering**

– **Jarvis-Judice-Ninke dithering**

– **Sierra 2-4a dithering**

– **Stucki dithering**

– **Burkes dithering**

– **Sierra2 dithering**

– **Sierra3 dithering**

For each algorithm, I wrote a 2-dimensional convolution function (a matrix passing over a matrix); it is *slow* because I didn’t implemented any fasting tricks. It can be easily implemented in C, then used in R for a faster solution.

Then, a function to transform a grey image in a grey-dithered image is provided, with an example. The library **rimage** was used for loading and displaying images (see the other post R is a cool image editor).

These function can be easily re-coded for a RGB image.

Only the first code is commented, ’cause they’re all very similar.

library(rimage)

y <- read.jpeg("valve.jpg")

plot(y)

__Floyd-Steinberg dithering__

plot(normalize(grey2FSdith(rgb2grey(y))))

__Bill Atkinson dithering__

plot(normalize(grey2ATKdith(rgb2grey(y))))

__Jarvis-Judice-Ninke dithering__

plot(normalize(grey2JJNdith(rgb2grey(y))))

__Sierra 2-4a dithering filter__

plot(normalize(grey2S24adith(rgb2grey(y))))

__Stucki dithering__

plot(normalize(grey2Stucki(rgb2grey(y))))

__Burkes dithering__

plot(normalize(grey2Burkes(rgb2grey(y))))

__Sierra2 dithering__

plot(normalize(grey2Sierra2(rgb2grey(y))))

__Sierra3 dithering__

plot(normalize(grey2Sierra3(rgb2grey(y))))

**leave a comment**for the author, please follow the link and comment on their blog:

**Statistic on aiR**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.