We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everybody! I am trying to blur my image over 10 frames. This is the coding for the blur. I have already set the frame rate, but it only changes quickly and not over 10 frames. Any ideas?
PImage blurImg = createImage(img2.width, img2.height, RGB);
//Loop through every pixel in the image
for (int y = 1; y < img2.height-1; y++) { // Skip top and bottom edges
for (int x = 1; x < img2.width-1; x++) { // Skip left and right edges
int loc = x + (y*img2.width); // Current pixel location
float sumr = 0; // Kernel sum for this pixel
float sumg = 0;
float sumb = 0;
for (int ky = -1; ky <= 1; ky++) {
for (int kx = -1; kx <= 1; kx++) {
// Calculate the adjacent pixel for this kernel point
int pos = (y + ky)*img2.width + (x + kx);
// Image is grayscale, red/green/blue are identical
float valr = red(img2.pixels[pos]);
float valg = green(img2.pixels[pos]);
float valb = blue(img2.pixels[pos]);
// Multiply adjacent pixels based on the kernel values
sumr += kernel[ky+1][kx+1] * valr;
sumg += kernel[ky+1][kx+1] * valg;
sumb += kernel[ky+1][kx+1] * valb;
}
}
// For this pixel in the new image, set the gray value
// based on the sum from the kernel
blurImg.pixels[y*img2.width + x] = color(sumr,sumg,sumb);
}
}
// State that there are changes to blurImg.pixels[]
blurImg.updatePixels();
image(blurImg, 0, 0); //Blur image
}
I'm very new to this, so sorry if its unclear.. Thank you!
Answers
You should keep the same PImage global, to preserve the last state between draw() calls. Ie. don't recreate it on each frame, act on it on each draw() call.