 |
Author |
Topic: ordered dither (Read 1194 times) |
|
Koenie
 

|
ordered dither
« on: Jul 28th, 2004, 10:08pm » |
|
I've made this little piece of code that uses an ordered dithering algorithm to make a colored image black and white. Anyway here's the code, it works with every image: Code:BImage img; float[] w; int[] m = {0,32,8,40,2,34,10,42,48,16,56,24,50,18,58,26,12,44,4,36,14,46,6,38,60, 28,52,20,62,30,54,22,3,35,11,43,1,33,9,41,51,19,59,27,49,17,57,25,15,47, 7,39,13,45,5,37,63,31,55,23,61,29,53,21}; int d = (int)sqrt(m.length); void setup() { img = loadImage("your_filename_here.ext"); size(img.width, img.height); w = new float[width*height]; colorMode(RGB,1); for (int i = 0; i < w.length; i++) w[i] = brightness(img.pixels[i]); } void draw() { for (int i = 0; i < w.length; i++) pixels[i] = (w[i]*d*d > m[i/width%d*d+i%width%d]) ? #FFFFFF : #000000; } |
| Here is an example to give you an idea of what the program does (the left image is the original image and the right image is the dithered version, I guess that makes sense): It also works with colored images, because it uses the brightness()-function to get the grayscale version of the pixels. If anyone is interested in how this code really works, I am willing to explain it. Koenie
|
« Last Edit: Jul 28th, 2004, 10:11pm by Koenie » |
|
http://koeniedesign.com
|
|
|
|