Blur / Filter only part of the image / canvas? (Masking?)

I have a large canvas and want to use the blur feature, but it’s too much for my computer to handle in real time. I only really care about the center of the canvas being blurred. (let’s say a circle with radius of 50 or a 100 x 100 square.) Can I apply the filter to just the middle of my canvas like a mask in photoshop?

Thank you! This is my first post, lmk if I should change something to fit post guidelines.

1 Like

You can grab a PImage of the center of your sketch with get(x,y,w,h);

You can then draw that image on an off-screen PGraphics (of the same size), blur it, and mask it.

Then draw the blurred circle over the original sketch.

PGraphics pg;
PImage img, msk;
size(400,400);
pg = createGraphics(200,200);
pg.beginDraw();
pg.clear();
pg.noStroke();
pg.fill(255);
pg.ellipse(100,100,175,175);
pg.endDraw();
msk = pg.get();
background(128);
for( int i = 0; i < 100; i++){
  fill(random(255),random(255),random(255));
  rect( random(width-20), random(height-20), 20, 20);
}
pg.beginDraw();
pg.image(get(100,100,200,200), 0,0);
pg.filter(BLUR,4);
pg.endDraw();
img = pg.get();
img.mask(msk);
image(img, 100, 100);
2 Likes