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 › Illuminate section of image
Page Index Toggle Pages: 1
Illuminate section of image (Read 691 times)
Illuminate section of image
Dec 31st, 2007, 2:42pm
 
Hello!

Is there a possibility to illuminate a part of an image.
I have two exactly same images except that one is black&white (this is the base image) and the other is colored.

I want to load a part of the colored image in a circle, wherever i move the mouse cursor.

I know how to do the moving stuff, but not the loading (overlaying) of images in the circle.

See example here (for better understanding):
http://shrani.si/f/1j/Zg/hQ1piMI/panoramac.jpg

Please help.

Thnx in advance!!!
Re: Illuminate section of image
Reply #1 - Jan 2nd, 2008, 8:45am
 
You could do this using the mask() method on the images to control their alpha channels:

PImage img;
PGraphics stencil;

void setup()
{
 img = loadImage("img.jpg");
 size(img.width, img.height);
 stencil = createGraphics( img.width, img.height, JAVA2D );
}

void draw()
{
 // draw a circle to the stencil at the mouse position
 stencil.beginDraw();
 stencil.background(0);
 stencil.ellipse(mouseX,mouseY,200,200);
 stencil.endDraw();

 // apply the stencil to a copy of the image
 PImage maskedImg = img.get();
 maskedImg.mask(stencil);
 
 // invert the stencil
 stencil.beginDraw();
 stencil.filter(INVERT);
 stencil.endDraw();
 
 // apply the inverted stencil to another copy for the background
 // and desaturate it
 PImage bgImg = img.get();
 bgImg.mask(stencil);
 bgImg.filter(GRAY);
 
 // draw our two images
 image(bgImg, 0, 0 );
 image(maskedImg, 0, 0);
}
Re: Illuminate section of image
Reply #2 - Jan 3rd, 2008, 8:41pm
 
Thank you very much!
Page Index Toggle Pages: 1