1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

Creating a spotlight effect

Posted by Andy Edmonds on Feb 25, 2007

I'm trying to use a mask to simulate foveal and non-foveal vision. Imagine a spot light that reveals full resolution with the rest of the image in reduced rez.

The reduced rez is working well with:
l.adjust_brightness(0.55)
l.filter_blur(2)

Though ideally this should also reduce color depth to black and white (256 greys would be lovely).

The part I'm having a hard time with is creating a mask/blend. I made a black and white png, filled with black with a transparent circle in the middle.

Applying the following after loading
l = canvas.layer("stimulus.png")
l.adjust_brightness(0.55)
l.filter_blur(2)
m = canvas.layer("pinhole.png")
m.blend(15, mode="screen")

Results in a grey and white image, not actually transparent. What am I doing wrong?

Is there a better way to create a circular pinhole? I'd like to be able to tranform it's size and apply differing levels of brightness/blur underneath it. I'm assuming I'll clone the stimulus png for that.

Mucho gracias.
Andy



Posted by Tom De Smedt on Feb 26, 2007

Hi Andy,

Assuming I understand correctly what you want to do, try the following:

coreimage = ximport("coreimage")
 
canvas = coreimage.canvas(500, 500)
 
l = canvas.layer("stimulus.jpg")
l.adjust_brightness(0.25)
l.filter_blur(2)
# Make this layer grayscale.
l.desaturate()
 
# Add a new layer with the color image.
l = canvas.layer("stimulus.jpg")
# Add a mask to the layer.
# A layer's mask is a canvas, so we can add sublayers to it.
# In this case, a radial gradient.
m = l.mask.layer_radial_gradient(spread=0.5)
# The mask's scale controls the visibility radius of the colored image.
m.scale(0.95)
 
canvas.draw()


Since the mask m is a layer like any other you can scale it, move it, rotate it, etc...

Let me know if that worked for you!