#color #image #level #dithering #pixel #square #io

dithor

Pixilisation/dithering library

5 unstable releases

0.3.1 Apr 26, 2023
0.3.0 Apr 13, 2023
0.2.1 Apr 2, 2023
0.2.0 Mar 7, 2023
0.1.0 Nov 17, 2022

#591 in Images

Download history 2/week @ 2024-02-16 8/week @ 2024-02-23 1/week @ 2024-03-01 1/week @ 2024-03-08 1/week @ 2024-03-15 67/week @ 2024-03-29

69 downloads per month

MIT license

18KB
426 lines

Dithor

What is this library

Basic principles

This library rewrite an image given as input using only two colors a la dithering.

The image is spit in many squares of 5x5 pixels. For each of those squares the average relative luminance is calculated.

This luminance is then used to assign a level to the square. The level is between 0 and 9, 0 for completely bright and 9 fully dark.

The content of the square is then filled with the following pattern (depending on the level) :

dithor gradiant for levels

Here's a picture showing the same patterns on a bigger surface :

dithor gradiant for levels

Finally here's an example using the painting "The swan, no 1" from Hilma af Klint :

dithor version of the swan

Using colors

When the third parameter is true the output will be in color, the brightest and darkest colors from the 25 pixels are used to fill the patterns showed above.

How to use it

Crate.io

To use this library you can simply call it using :

dithor::dithor("input.jpg", "output.jpg", true, true);

Params

  • input: path to the input image, can be a jpg or png
  • output: path to the output image, can be a jpg or png. If the file already exists it will be overwritten
  • overwrite: specify if the output file should overwrite any existing image with the same name
  • color: boolean, if true the output image will be in color otherwhise it will be in black and white

Dependencies

~13MB
~60K SLoC