| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is often one of the last stages of mastering audio to a CD.
A common use of dither is converting a greyscale image to black and white, such that the density of black dots in the new image approximates the average grey level in the original.
Source: Dither. From Wikipedia, the free encyclopedia
This free and simple to use class helps you to integrate a dithering filter into your project in no time. Copy either the contents of DitherClass.pde into a new tab or simply the whole DitherClass.pde file into your Processing project.
Currently there are four modes available:
Simple Example
Dither d;
Dither d2;
PImage p;
void setup() {
size(800, 800);
surface.setLocation(0,0);
colorMode(HSB, 360, 100, 100);
p = loadImage("medusa.jpg");
d = new Dither();
d2 = new Dither("sample.jpg");
d.setCanvas(400, 400);
d.feed(p);
// example of how to set the modes differently via d2 object
d2.setMode("RANDOM");
d2.setMode(3);
}
void draw() {
background(255);
image(d.floyd_steinberg(), 0, 0);
image(d.bayer(), 0, 400);
image(d.atkinson(), 400, 0);
image(d.rand(), 400, 400);
// get random outputs
d2.setMode((int)random(4));
// ask the dither object just for the calculated dither image instead of going to a mode directly
image(d2.dither(), 200, 200);
}
| Class | Parameters | Description |
|---|---|---|
| Dither | empty | Creates a new dither object with some standard dimensions. I used this for my flipdots :) |
| Dither | String s | Loads an image from your data folder and takes the dimensions to create the PGraphics buffer |
| Dither | int w, int h | Creates the dither objects with dimensions w and h |
| Method | Return | Parameters | Description |
|---|---|---|---|
| setCanvas | void | int w, int h | Creates a new PGraphics buffer with dimensions w and h. The dithering will be applied to the contents of the Buffer |
| setMode | void | int m | Sets the internal mode. Allowed input: 0, 1, 2, 3 => floyd, bayer, atkinson, random |
| setMode | void | String s | Set the mode. Input: "FLOYD", "BAYER", "ATKINSON", "RANDOM" |
| feed | void | PImage | Set the internal source of the class (such as an PImage that you load or the current frame of a Movie object) |
| dither | PGraphics | empty | Returns the current internal source with the setMode parameters |
| dither | PGraphics | int m | Returns the current internal source. Input: 0,1,2,3 |
| floyd_steinberg | PGraphics | empty | Returns the current internal source with Floyd-Steinberg dithering |
| bayer | PGraphics | empty | Returns the current internal source with Ordered (Bayer) dithering |
| atkinson | PGraphics | empty | Returns the current internal source with Atkinson dithering |
| random | PGraphics | empty | Returns the current internal source with random dithering |
| findClosestColor | color | color c | Threshold function that computates the closest color. Currently hardcoded to do brightness calculations only. |
All image sources will be cast into RGB color space. This will still work with Processing sketches, that are explicitly working with HSB colorMode!
| Back | FazBrowse Home | New Git URL |