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

get the color of a pixel

Posted by ilmeditafuga on Feb 16, 2010

HI!

I am a newbie and I try to get a color from a pixel of my image.
I am sorry if is not a great question but I doesnt found how to.

M.


 
Posted by Frank "Buddy" Morris on Feb 17, 2010

There may be more efficient ways of doing it but, this is the way I 've cobble together. This code will get the color information for a pixel at 200x200 in an image called bud.jpg. The printed result looks like this: Color(0.129, 0.145, 0.186, 1.000)

Hope this helps.....

coreimage = ximport("coreimage")
x = 200
y = 200
canvas = coreimage.canvas(150,150)
l = canvas.append("bud.jpg", w= 800)
p = l.pixels()
clr = p.get_pixel(x,y)
print clr



Posted by Tom Fuerstner on Feb 17, 2010

size(400, 400)
colors = ximport("colors")
coreimage = ximport("coreimage")

canvas = coreimage.canvas(400, 400)
layer = canvas.layer("imageName.png")
pixel = layer.pixels()
pColor = pixel.get_pixel(x, y)



Posted by Tom Armstrong on May 27, 2010

I'd also like to know about this -

The coreimage .get_pixel method returns a Color() object.
I'd like to test if that Color() is black, I guess using the .is_black property from the Colors library.

How would I go about doing this? I'm a newb, can't work out how to use the Color() that .get_pixel returns with the .is_black property from the Colors library.



Posted by Stefan on May 27, 2010

Adding to the example above, you can do:

print colors.color(pColor).is_black



Posted by gari on Sep 08, 2011

I'm trying to get a color from an image file.For example I have a grey image with rgb values (128,128,128).
If I use the get_pixel command it comes up with a value of Color(0.565, 0.565, 0.565, 1.000).
I expected to get Color(0.5, 0.5, 0.5,1.000)
All colors seem to come out much brighter than in the original image. What am I doing wrong?