Why is filter(BLUR) so slow?

I have been using the funtion "filter(BLUR)" for use in images and videos.

Why is it so slow? I am used to Gaussian Blur with Quartz Composer, After Effects, etc. It is usually very fast and simple.

Why is it so slow? I am using a top of the line Mac Book Pro and I am getting 5-6 FPS on a blur operation of a simple ellipse. I would expect it to run much faster than this. However, I feel there is a simple solution or I am missing something basic.

Is there a better way to apply blur? A better library? Any suggestions are appreciated!

// Why is blur so slow?
// Casey Scalf 2015
// www.Sensebellum.com

void setup()  {
  size(1280, 720);
  frameRate(30);
  background(0);
}

void draw()  {
  background(0); // Remove for additive blur
  fill(127);
  stroke(255);
  ellipse(mouseX, mouseY, 50, 50);

  filter(BLUR, 2);

  println("FPS: " + frameRate);
}
Tagged:

Answers

  • Answer ✓

    Hello ! You're right, it's weird.... But you can use the one given in the examples. It's based on a custom shader and it works very well and smoothly

  • That filter is done on the cpu. Try to find a blur shader that works on the gpu. There should be one with the processing examples.

  • As said: the base blur is done with looping on the pixels and doing a pixel group operation. Lot of work.
    A blur done with a shader is delegated to the GPU, so it should be painless...

  • edited June 2015

    http://forum.processing.org/two/discussion/comment/44025/#Comment_44025

    // forum.processing.org/two/discussion/11141/why-is-filter-blur-so-slow
    
    PImage blurImg;
    
    void setup() {
      size(1280, 720, JAVA2D);
    
      smooth(4);
      noCursor();
      noLoop();
      frameRate(60);
      imageMode(CENTER);
    
      blurImg = blurredEllipse(50, 0200, #FFFF00);
    }
    
    void draw() {
      background(0);
      image(blurImg, mouseX, mouseY);
    }
    
    void mouseMoved() {
      redraw = true;
    }
    
    PImage blurredEllipse(int diam, color ink, color outline) {
      final PGraphics pg = createGraphics(diam + 5, diam + 5, JAVA2D);
      pg.beginDraw();
    
      pg.smooth(4);
      pg.fill(ink);
      pg.stroke(outline);
      pg.strokeWeight(2);
    
      pg.ellipseMode(CENTER);
      pg.ellipse(diam>>1, diam>>1, diam, diam);
      pg.filter(BLUR, 2);
    
      pg.endDraw();
      return pg.get();
    }
    
  • That's doing the blurring in setup which is no use for a dynamic sketch.

  • Love the responses everybody, thank you for the tips. The CPU vs GPU distinction is very good to note. I was sure there was a faster way to do it. I will play around with putting this in my code a little bit later tonight.

Sign In or Register to comment.