Skip to content

Instantly share code, notes, and snippets.

@z3a
Forked from decolector/color_quantizer
Created March 19, 2014 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z3a/9635202 to your computer and use it in GitHub Desktop.
Save z3a/9635202 to your computer and use it in GitHub Desktop.
size(160 * 3, 160 * 3);
PImage img;
colorMode(RGB, 5);
img = loadImage("gray_5.jpg");
loadPixels();
float cms = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
noFill();
stroke(0);
//img.loadPixels();
image(img, 0, 0);
background(0);
println("image pixels");
for (int i=0; i<img.width; i ++ ) {
for (int 0; j<img.height; j ++ ) {
int loc = i + j*img.width;
int col = int(red(img.pixels[loc])) + 1;
cms = cms + col * 0.5;
println("i: " + i + ", j: " + j + ", col: " + int(col));
switch(col){
case 1:
a++;
stroke(#DED055);
fill(#DED055);
text('5', (i*30) + 10, (j*30) + 10);
noFill();
rect(i*30, j*30, 30, 30);
break;
case 2:
stroke(#86DE55);
fill(#86DE55);
text('4', (i*30) + 10, (j*30) + 10);
noFill();
rect(i*30, j*30, 30, 30);
b++;
break;
case 3:
stroke(#0B97BC);
fill(#0B97BC);
text('3', (i*30) + 10, (j*30) + 10);
noFill();
rect(i*30, j*30, 30, 30);
c++;
break;
case 4:
stroke(#D627D3);
fill(#D627D3);
text('2', (i*30) + 10, (j*30) + 10);
noFill();
rect(i*30, j*30, 30, 30);
d++;
break;
case 5:
stroke(#E81031);
fill(#E81031);
text('1', (i*30) + 10, (j*30) + 10);
noFill();
rect(i*30, j*30, 30, 30);
e++;
break;
}
}
}
println("total cms: " + cms);
println("color 1: " + a);
println("color 2: " + b);
println("color 3: " + c);
println("color 4: " + d);
println("color 5: " + e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment