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 › question about filters
Page Index Toggle Pages: 1
question about filters (Read 794 times)
question about filters
Feb 18th, 2007, 4:07am
 
Hello have a question about the way filters are applied in Porcessing.
Here's the code.


void setup()
{
 size(1000, 350);
 
 PImage BaseImage, Image2Filter;  
                         
 BaseImage=loadImage("shark.jpg");
 
 Image2Filter=BaseImage;                //copy all the pixels and start manipulating the copy,
                                        //this way I think I will always have the original to go back to
               
 Image2Filter.filter(GRAY);              //apply filter to the image file
 image(Image2Filter,0,0);  
   
 Image2Filter=BaseImage;                //once again copy from the original
               
 image(Image2Filter,500,0);    
   
}

I assumed that I would get the filtered version next to the original but all i get are two filtered images. hmm... Can someone enlighten me as to what I am doing wrong here?

I am fairly new to processing so appologise if I am missing something basic.

thnx
         d
Re: question about filters
Reply #1 - Feb 18th, 2007, 2:24pm
 
In your code, you only ever create one PImage object (the loadImage() function "constructs" the PImage).  Even though you have two variables -- BaseImage and Image2Filter -- when you set Image2Filter equal to BaseImage, what you are saying is "Both of these variables refer to the same Image object."   This is *not* making a copy of the image.  To do that you need to use the copy() function.

http://processing.org/reference/copy_.html

You could also just load the file twice as a quick solution:

Code:

PImage BaseImage, Image2Filter;
// Make two distinct PImage objects!
BaseImage=loadImage("shark.jpg");
Image2Filter = loadImage("shark.jpg");

Image2Filter.filter(GRAY);
image(Image2Filter,0,0);
image(BaseImage,500,0);
Re: question about filters
Reply #2 - Feb 18th, 2007, 3:12pm
 
to make a copy you actually use get(), ala:
baseImage=loadImage("shark.jpg");
image2Filter = baseImage.get();

get() with no parameters is simply the same as:
baseImage.get(0, 0, baseImage.width, baseImage.height).

which will produce a copy of the image. unfortunately, copy() only copies a section of the image, and doesn't create a new image.
Re: question about filters
Reply #3 - Feb 18th, 2007, 7:29pm
 
Thank you for the explanation. OO programming is still a bit of a mistery to me Smiley

Will implement your suggestion.  

d
Page Index Toggle Pages: 1