PImage img; int w = 510; void setup() { size(510, 410); frameRate(30); img = loadImage("bunt.jpg"); image(img,0,0); loadPixels(); } void draw() { // Rechteck definieren, das veraendert wird int xstart = constrain(mouseX-w,0,img.width); int ystart = constrain(mouseY-w,0,img.height); int xend = constrain(mouseX+w,0,img.width); int yend = constrain(mouseY+w,0,img.height); // Matrix definieren int matrixsize = 3; float[][] matrix = { { -1, -1, -2 }, { -1, 9, -1 }, { -2, +1, -1 } }; // Pixel holen und neu definieren for (int x = xstart; x < xend; x++) { for (int y = ystart; y < yend; y++ ) { color c = convolution(x,y,matrix,matrixsize,img); int loc = x + y*img.width; pixels[loc] = c; } } updatePixels(); } // Convolution definieren color convolution(int x, int y, float[][] matrix,int matrixsize, PImage img) { float rtotal = 0.0; float gtotal = 0.0; float btotal = 0.0; int offset = matrixsize / 2; for (int i = 0; i < matrixsize; i++) { for (int j= 0; j < matrixsize; j++) { int xloc = x+i-offset; int yloc = y+j-offset; int loc = xloc + img.width*yloc; loc = constrain(loc,0,img.pixels.length-1); // Convolution berechnen if (mouseX < 250) { if (mouseY < 200) { // Convolution rot rtotal += (red(img.pixels[loc]) * 6 ); gtotal += (green(img.pixels[loc]) * matrix[i][j]); btotal += (blue(img.pixels[loc]) * matrix[i][j]); } else { // Convolution blau rtotal += (red(img.pixels[loc]) * matrix[i][j]); gtotal += (green(img.pixels[loc]) * matrix[i][j] ); btotal += (blue(img.pixels[loc]) * 6); } } else { if (mouseY < 200) { // Convolution gruen rtotal += (red(img.pixels[loc]) * matrix[i][j]); gtotal += (green(img.pixels[loc]) * 4); btotal += (blue(img.pixels[loc]) * matrix[i][j]); } else { // Convolution gelb rtotal += (red(img.pixels[loc]) * 6 ); gtotal += (green(img.pixels[loc]) * 6); btotal += (blue(img.pixels[loc]) * matrix[i][j]); } } } } // RGB der Farben innerhalb Farbrahmen rtotal = constrain(rtotal,0,255); gtotal = constrain(gtotal,0,255); btotal = constrain(btotal,0,255); // Farben der Convolution ausgeben return color(rtotal,gtotal,btotal); }