Re: [Pyobjc-dev] Displaying a numpy array
Brought to you by:
ronaldoussoren
|
From: Black <py...@bl...> - 2009-04-01 19:33:45
|
On Apr 1, 2009, at 2:34 PM, Thomas Robitaille wrote: >> In fact, displaying a PIL image is pretty simple in OpenGL and the >> whole ObjC side could be side stepped. I'm curious what is meant by >> "displaying a numpy array". There are many ways one could "display" >> an array in OpenGL. If it contains bitmap data then you could just >> use PyOpenGL again. If it is arbitrary data, one could visualize it >> by mapping the values to visual glyphs. There is nothing >> particularly visual about arrays of numbers however, so I'm not >> sure what is meant by "display the contents"... > > I should have been clearer. Essentially, I am reading an image (in > FITS format) using a specific module which stores the image in a > numpy array. I can easily convert this to a PIL image if need be. > > What I would like to do is to show this image inside an interface > with buttons and text fields, which is why I was interested in using > PyObjC to do this rather than pyopengl alone. Since I sent my > original email to this list, I've realized that this could also be > down with a Quartz Composer item inside the interface. > > Which would be easiest, and either way, does anyone know of any > examples of showing an image (from an array, whether numpy or PIL) > inside an interface build in the 'Interface Builder'? I sort of > understand the default PyObjC OpenGL example, but not enough to make > it show an image instead of just a solid color. > > Any advice/examples would be welcome! If you figured out how to do this with Quartz Composer, I'd say go ahead and do it that way, you will probably get more support from the API that way - especially if you've never worked with OpenGL before. OpenGL is pretty much like the C of the graphics world - not exactly the highest level way to do things. That said if you want to go the OpenGL way, you have two basic options: glDrawPixels(), which just rasterizes your image onto the display or Load the image into a texture and map it to a quad. Either one would work, texture mapping is a little more involved, but probably a little more robust. Either way, I'd load your data through PIL - PIL has some nice methods for extracting bits in reasonable formats, which is essential for using either of those techniques. |