R is a cool image editor #2: Dithering algorithms

August 29, 2011

(This article was first published on Statistic on aiR, and kindly contributed to R-bloggers)

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.

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

Floyd-Steinberg dithering


Bill Atkinson dithering


Jarvis-Judice-Ninke dithering


Sierra 2-4a dithering filter


Stucki dithering


Burkes dithering


Sierra2 dithering


Sierra3 dithering


To leave a comment for the author, please follow the link and comment on his blog: Statistic on aiR.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.