Quote:color convolut(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; //we need an offset to start at the topleft of the matrix
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; i++) {
int xloc = x + i - offset; //get xpos in kernel
int yloc = y + j - offset; //get ypos in kernel
int loc = xloc + img.width*yloc; //get the current pixel
loc = constrain(loc,0,img.pixels.length-1);
//Source * Image = new color for the tested pixel!
println(i);
//rtotal += (red(img.pixels[loc]) * matrix[i][j]);
//gtotal += (green(img.pixels[loc]) * matrix[i][j]);
//btotal += (blue(img.pixels[loc]) * matrix[i][j]);
}
}
//make sure rgb is in range
rtotal = constrain(rtotal,0,255);
gtotal = constrain(gtotal,0,255);
btotal = constrain(btotal,0,255);
//return the color
return color(rtotal,gtotal,btotal);
}
Hello everyone,
Currently I've been getting my head around the convolution example by Shiffman, and just when I thought I understood the process of multiplying two arrays I got stuck with some odd behaviour.
Against my expectations variable i and j contain far larger numbers. Nowhere in the code do I use these vars, so I really don't understand where they get their values.
And as per the title, for obvious reasons if I uncomment the actual rtotal(etc) equations I get an out of bounds error.
Someone knows/sees what's going on.
Thnx in advance.