Skip to content

Instantly share code, notes, and snippets.

@decolector
Created March 18, 2014 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save decolector/9631438 to your computer and use it in GitHub Desktop.
Save decolector/9631438 to your computer and use it in GitHub Desktop.
Measure pixel distribution per color.
size(16, 16);
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;
//image(img, 0, 0);
background(img);
println("image pixels");
for (int i=0; i<img.width; i ++ ) {
for (int j=0; j<img.height; j ++ ) {
int loc = i + j*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++;
break;
case 2:
b++;
break;
case 3:
c++;
break;
case 4:
d++;
break;
case 5:
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