int blurWidth = 15;
void setup(){
size(512, 512);
noStroke();
PImage image = loadImage("lena.jpg");
image(image, 0, 0);
loadPixels();
color[][] colors = new color[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
colors[x][y] = pixels[y * width + x];
}
}
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
if(x < blurWidth || x > width - 1 - blurWidth ||
y < blurWidth || y > height - 1 - blurWidth){
pixels[y * width + x] = color(0);
} else {
float colorR = 0;
float colorG = 0;
float colorB = 0;
for(int xx = x - blurWidth; xx <= x + blurWidth; xx++){
for(int yy = y - blurWidth; yy <= y + blurWidth; yy++){
colorR += red(colors[xx][yy]);
colorG += green(colors[xx][yy]);
colorB += blue(colors[xx][yy]);
}
}
pixels[y * width + x] = color(colorR / sq(blurWidth * 2 + 1), colorG / sq(blurWidth * 2 + 1), colorB / sq(blurWidth * 2 + 1));
}
}
}
updatePixels();
}