quinta-feira, 18 de junho de 2015

Histograma

A aplicação seguinte mostra o histograma dos canais RGB (do azul ao vermelho) da imagem mostrada.

Imagem:
















Código:

int [] tons = new int[256];
PImage img;

void setup() {
  size(640, 480);
  int pos, t;
  img = loadImage("sora.jpg");
  for (int x = 0; x < 640; x++) {
    for (int y = 0; y < 480; y++) {
      pos = y*480 + x;
      t = (int)red(img.pixels[pos]);
      tons[t] = tons[t] + 1;
    }
  }
  int maior = tons[0];
  int tom = 0;
  for (int i =1; i<256 i="">
    if (tons[i]>maior) {
      maior = tons[i];
      tom = i;
    }
  }
    for (int i =0; i<256 i="">
    float tamanho = (tons[i]*height)/maior;
    fill(0);
    rect(i*2, height-tamanho, 2, height );
  }
}

Resultado:

Nenhum comentário:

Postar um comentário