We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Applying blur to the image
Page Index Toggle Pages: 1
Applying blur to the image (Read 956 times)
Applying blur to the image
Apr 27th, 2010, 3:26am
 
Hi,
I'm asking you for help with my program.
Program is applying a blur filter to an image.
It reads numeric keys from '0' to '5' and apply blur with level equal to the value of choosen number (0 - 5).
Now, the blur filter always modify source image and then next blur is applied to blured image.
I would like to always blur fresh original image...

here is example:
Code:

PImage img;

void setup() {
size(256,256);
img = loadImage("image.bmp");
img.loadPixels();
}

void draw() {
}

void blur(PImage imageb, int threshold) {
imageb.filter(BLUR, threshold);
image(imageb, 0, 0);
}

void keyPressed() {
if(key == '0') blur(img, 0);
if(key == '1') blur(img, 1);
if(key == '2') blur(img, 2);
if(key == '3') blur(img, 3);
if(key == '4') blur(img, 4);
if(key == '5') blur(img, 5);

redraw();
}



How to make it works ?
Everytime the blur(); function is called i want to modify source image with current ammount of blur.
PLEASE HELP Smiley
Re: Applying blur to the image
Reply #1 - Apr 27th, 2010, 4:45am
 
Try setting blur(img, 0); first every time keyPressed()

Cheers
rS
Re: Applying blur to the image
Reply #2 - Apr 27th, 2010, 4:55am
 
Have another PImage with the original image, and before each blur, copy the original to the PImage to blur.
Re: Applying blur to the image
Reply #3 - Apr 27th, 2010, 5:36am
 
Copying image doesn't work !
I've noticed that copying method has some bug.
Copied image is a bit difrent than original. I dont know why but it is true.

I solved this problem using my own function (create new image and copy each single pixel from original to the new one)

Code:

for(int i=0; i <original_image.pixels.length; i++)
new_image.pixels[i] = original_image.pixels[i];


I'm wondering if it can be done simplier way...
?
Re: Applying blur to the image
Reply #4 - Apr 27th, 2010, 6:28am
 
10production wrote on Apr 27th, 2010, 5:36am:
Copying image doesn't work !
I've noticed that copying method has some bug.
Copied image is a bit difrent than original. I dont know why but it is true.

It depends on how you do the copy...
Using get() should make an exact copy in a way similar to the one you show, just more efficient...
Page Index Toggle Pages: 1