Calculation the color density of an image

Hi There,

Is there a way to calculate the percentages of the colors in an image, for example in a logo.
If it is possible i want to translate those color percentage values into rectangles.
I hope to hear from you.
Kind regards in advance!

Hello @jaspervb ,

Yes. You will have to write some code to do this or find a solution out there that already does this.

Here are some tutorials to get you started:

There are also resources (tutorials, references, examples) here:


1 Like

Hello @jaspervb,

An incomplete example which I started with to plot a distribution of hues:

// Color Distribution
// v1.0.0
// GLV 2022-12-04

PImage img;
int [] col = new int [60];

void setup()
  size(600, 600);
  colorMode(HSB, 60, 100, 100);
  img = loadImage("");
  println(img.width, img.height);
  for(int i= 0; i<img.pixels.length; i++)
    // Extract the hues (0 to 60) and add to col[]
  image(img, 300, 200);
void draw()

Have fun!


1 Like

Can you probably help me with your example. I don’t know how to make those colored lines wich i see in your image

you want to display this array as lines:

int [] col = new int [60];

for the lines use rect:

Pseudo code:

for ( i .... ) {
    fill( i ); 
    rect ( i * width / 60.0, 0 , 
            width / 60.0,  col[i] ); 

There is a histogram example on the Processing website.


1 Like