# dithr package for error diffusion dithering in R

## Introduction

I made a simple package to encapsulate the dithering code from yesterday’s post.

The package is called dithr and is available on github

The code expects a numeric matrix (all values in the range [0, 1]) as input and provides a matrix as output with only 0 and 1 values. It includes 10 pre-defined diffusion matrices in dithr::diffusion_matrix.

At the moment it’s not really very user friendly, mostly because dealing with image data in R can be a bit of a pain.
There’s probably a great set of image packages out there I haven’t discovered yet! (let me know!)

Intallation

devtools::install_github('coolbutuseless/dithr')

Packages

• magick - for image preparation
• EBImage - easiest(?) way to get image data out of magick

To Do

• Serpentine error diffusion (i.e. alternating traversal direction every row)

## Create a ggplot and save it as a PNG

p <-  ggplot(iris) +
geom_histogram(aes(Sepal.Length, fill=Species), bins=10) +
scale_fill_brewer() +
theme_bw() +
theme(legend.position='none')

ggsave("hist.png", width=6, height=4, units = 'in', dpi = 100)

p