Loading...
Logo
Processing Forum
This is something I've been curious about for a while but never was never quite able to figure out. There are few examples online using convolution kernels to create blurring and other effects, but one thing was bugging me; How would it be possible to have a static image in processing, mouseclick in a certain area gradually blurring that small section of the image?
 
Id be very interested to hear of anyones attempt at trying to do this or anything similar :)
 
PS Itd be very cool to see methods for motion blurring if anyone knows of any!
 
Cheers
 
-Dave

Replies(7)

Challenge accepted!

Right so here is what i guess you were asking for, getting the circular fall-off to look good was a pain in the... but here it is

Copy code
  1. PImage img;
  2. PImage temp;
  3. float[][] kernel = {{1,2,1},{2,4,2},{1,2,1}};
  4. int blurRect = 50;
  5. float blurRage = dist(blurRect-10,blurRect-10,0,0); //don't change this
  6. void setup(){
  7.   img=loadImage("image.jpg");
  8.   temp = createImage(img.width,img.height,ARGB);
  9.   temp.set(0,0,img);
  10.   size(img.width,img.height);
  11. }
  12. void draw(){
  13.   image(img,0,0);
  14. }
  15. void mouseDragged(){
  16.   for(int y = max(mouseY-blurRect-1,1);y<min(mouseY+blurRect+1,height-1);y++){
  17.     for(int x = max(mouseX-blurRect-1,1);x<min(mouseX+blurRect+1,width-1);x++){
  18.       float rsum = 0;
  19.       float gsum = 0;
  20.       float bsum = 0;
  21.       float a = min((dist(mouseX,mouseY,x,y)+5)/blurRage,1);
  22.       for(int h = 0; h<3;h++){
  23.         for(int w = 0; w<3;w++){
  24.           color c = img.get(x+w-1,y+h-1);
  25.           rsum += red(c)*kernel[w][h];
  26.           gsum += green(c)*kernel[w][h];
  27.           bsum += blue(c)*kernel[w][h];
  28.         }  
  29.       }
  30.       color c = img.get(x,y);
  31.       rsum /= 15.95;
  32.       gsum /= 15.95;
  33.       bsum /= 15.95;
  34.       rsum = (rsum*(1-a)+red(c)*a);
  35.       gsum = (gsum*(1-a)+green(c)*a);
  36.       bsum = (bsum*(1-a)+blue(c)*a);
  37.       temp.set(x,y,color(rsum,gsum,bsum));
  38.     }
  39.   }
  40.   img.set(0,0,temp);
  41. }
Wow :) Very Nice.
 
Thats Just what I meant!
 
btw
Copy code
  1. rsum /= 15.95;
just to make things clear 15.95 is: the sum of all numbers in the kernel minus 0.05
LOL yeah im still reading though it bit by bit to get an understanding. Just trying to grasp how you got the circle brush on the mouse cursor hehe.
 
Good Stuff.
BJordal,
 
Do you know of any good websites or books that can explain the use of convolution kernels for these kind of effects?
 
Thanks
 
-Dave