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 › How to apply the filter() function partially
Page Index Toggle Pages: 1
How to apply the filter() function partially? (Read 353 times)
How to apply the filter() function partially?
May 20th, 2008, 4:48pm
 
Hi guys,
   I'm still in the process of learning how to use processing. I wanted to apply the filter() function to only part of an image that I have loaded and I can't find anything in the library that would allow me to do that. Can anyone help me please?
Re: How to apply the filter() function partially?
Reply #1 - May 20th, 2008, 9:43pm
 
I love this kind of question: they are easy enough for me to solve, and it makes me research the reference, as I am still new to Processing.

I found that filter() is either a function acting on the whole display, or a method of PImage, acting on such image.
So the solution I found is as follow:
Code:
// Unlike what the reference says, absolute paths work. Except in applets. And it is not portable, of course!
PImage niceImage = loadImage("D:\\_PhiLhoDocs\\DA\\SurfStyle.jpg");
// Dimension to image size
size(niceImage.width, niceImage.height);
// Display whole image
image(niceImage, 0, 0);
// Create a sub-image
// Starting at 20% of top-left sides
int posX = int(niceImage.width * 0.2);
int posY = int(niceImage.height * 0.2);
// And at 20% of bottom-right sides (100%-20%-20% = 60%)
int subWidth = int(niceImage.width * 0.6);
int subHeight = int(niceImage.height * 0.6);
// Create a sub-image of the needed size
PImage subImage = createImage(subWidth, subHeight, RGB);
// Copy a part of the main image into the sub-image
subImage.copy(niceImage, posX, posY, subWidth, subHeight, 0, 0, subWidth, subHeight);
// Apply the filter
subImage.filter(INVERT);
// And display the sub-image over the main one (the display)
image(subImage, posX, posY, subWidth, subHeight);

Perhaps there is more elegant way to do this which I overlooked.
Otherwise, this code snippet should be wrapped in a function for easier reuse.
Page Index Toggle Pages: 1