Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to scale and display an image in Python?

I am required to display a two dimensional numpy.array of int16 at 20fps or so. Using Matplotlib's imshow chokes on anything above 10fps. There obviously are some issues with scaling and interpolation. I should add that the dimensions of the array are not known, but will probably be around thirty by four hundred.

These are data from a sensor that are supposed to have a real-time display, so the data has to be re-sampled on the fly.

like image 587
Knut Eldhuset Avatar asked Sep 22 '08 12:09

Knut Eldhuset


1 Answers

The fastest way to display 30x400 data points is to:

Use OpenGL color arrays

If you can quickly transform your data to what OpenGL understands as color array, you could create a vertex array describing quads, one for each sensor, then update your color array and draw this orthographically on screen.

Use OpenGL textures

If you can quickly transform your datapoints to an opengl texture you can draw one quad with fixed UV coordinates that is bound to this texture.

Use pygame

Pygame has support for conversion of Numpy/Numarray to surfaces, Pygame can then transform such surfaces which involves resampling, after resampling you can blit it on screen.

Misc

pyglet makes dealing with opengl very easy

like image 89
Florian Bösch Avatar answered Oct 02 '22 06:10

Florian Bösch