Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Processing – Histogramm

Februar 23, 2012


PImage img;
boolean showPic = true;
int[] r, g, b;
int maxColor;

void setup() {
img = loadImage("hunde.jpg");
size(img.width, img.height);

r = new int[256];
g = new int[256];
b = new int[256];

loadPicture();
noStroke();
smooth();

}

void loadPicture() {
// new pixels
img.loadPixels();
// get pixels
for (int x = 0; x < img.width; x++ ) {
for (int y = 0; y</pre>
<img alt="" />
<pre> maxColor) {
maxColor = g[i];
}
if(b[i] &gt; maxColor) {
maxColor = b[i];
}
}

}

void draw() {
background(0);
image(img, 0, 0);
if (!showPic) {
fill(0,200);
rect(0,0,width,height);
for (int i = 0;i&lt;r.length;i++) {
stroke(255, 0, 0,200);
line(i*2, height, i*2, height-r[i]*height/maxColor);
stroke(0, 255, 0,200);
line(i*2, height, i*2, height-g[i]*height/maxColor);
stroke(0, 0, 255,200);
line(i*2, height, i*2, height-b[i]*height/maxColor);
}
}
}

void keyPressed() {
if (key == &#039; &#039;) {
showPic = !showPic;
}
}