Is really matplotlib this slooow for displaying images ? (sorry again)

Hi,

after some successful attempt at migrating routines from several plotting
and/or analysing softwares (pgplot, Midas, Iraf, etc) to Matplotlib
I now hit a big wall: the speed at which it can display a reasonably large image:

- I have a ''local'' library to read fits files [2D images] in python (after SWIG wrapping).
It converts these files into float - nmerix - arrays. I was then testing the ability
of matplotlib to display these 2D arrays.
Until now all was fine since I tested matplotlib on very small images (50x50 pixels).

Yesterday I tried with a 1600x1600 pixels image. NOTE: this is a very reasonable
size (and typical) in my work and I expect much much bigger ones in a near future
(up to 20 000 x 20 000).

==> Matplotlib takes ~20 seconds to display it !!!
  (after 12 seconds the window opens, and then it takes
  another 8 seconds to be displayed)

(as compared to less than .2 sec for Midas, Iraf and others so a factor of 100 at least!!!
and less than a second using the ppgplot routines).

Some info:

running on a 1.6 Ghz/512 RAM centrino, linux, backend TkAgg, numarray, float array of 1600x1600 pixels.
Using either imshow or figimage in ''ipython -pylab'' (tried different interpolation schemes
the one I want being ''nearest'' in general)

To be frank, this is a killer for me, since I need to work on such images
(signal processing, analysing) and display them each time changing the
levels, centring etc etc. There is no way I will wait for 1 mn for 3 successive displays...

So the question now:
- am I doing something wrong (backend, way to load the array, ...) or is it
  intrinsic to matplotlib ?
- is there a way out? (basically the same question..)

If there is no way out, I may have to just abandon (sigh) matplotlib for displaying images.
But if there is one, please let me know!!

Thanks

Eric

···

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem

Hi Eric,

I am certain that John will be very delighted
to have another of the "matplotlib is slow" e-mails ;-).
Let me therefore add my 2 cents on this before he
wakes up (hope I have the timezones right)
and gives a qualified comment on this ...

[... timings etc snipped ... ]

Some info:

running on a 1.6 Ghz/512 RAM centrino, linux, backend TkAgg, numarray,
float array of 1600x1600 pixels.
Using either imshow or figimage in ''ipython -pylab'' (tried different
interpolation schemes
the one I want being ''nearest'' in general)

Did you also try a Numeric array?
Another point: the imshow routine
has quite a bit of functionality
(color maps, interpolation, even alpha!!!)
which might cost some time (for example, I don't
know whether all this is done in python).
You can also pass a PIL (Python Image Library) image
to imshow.
So I would suggest:
  a) try a Numeric array
  b) try to convert you matrix to a PIL image
     and determine the time it takes to display that.
     (I would hope that this is much faster)

To be frank, this is a killer for me, since I need to work on such images
(signal processing, analysing) and display them each time changing the
levels, centring etc etc. There is no way I will wait for 1 mn for 3
successive displays...

So the question now:
- am I doing something wrong (backend, way to load the array, ...) or is it
  intrinsic to matplotlib ?

To really answer this question it would be useful
if you post your code (presumably simplified
by creating some mock data without reading from an external file).
By this one could also try this on other platforms ...

[...]

Best,

Arnd

···

On Mon, 20 Dec 2004, Eric Emsellem wrote:

Sorry to get into this discussion so late.

sterday I tried with a 1600x1600 pixels image. NOTE: this is a very reasonable
size (and typical) in my work and I expect much much bigger ones in a near future
(up to 20 000 x 20 000).

Wow, I want your 20Kx20K image display! Seriously, it sounds like you do not intend to display the whole thing at once. In that case I would consider doing the slicing and reduction outside of matplotlib and then displaying the subsampled or sliced region using the size of the window. Applying color transformations on the whole image is going to result in a lot of wasted cpu time. I also recognize that 1.6K^2 displays are not that unreasonable so reasonable performance with this size is something one wants to achieve.

==> Matplotlib takes ~20 seconds to display it !!!
(after 12 seconds the window opens, and then it takes
another 8 seconds to be displayed)

As John later alluded to, the time for the window to come up is a one time cost if you are running from an interactive prompt. It shouldn't be paid for subsequent display updates.

(as compared to less than .2 sec for Midas, Iraf and others so a factor of 100 at least!!!
and less than a second using the ppgplot routines).

For better understanding the comparison, when you use Midas, what are you displaying to? It's been a long, long, time since I've used Midas so I forget (or likely, it's changed) how image display is done. Are you using DS9, ximtool or SAOIMAGE? Or a different display mechanism?

By the way, we do have a module that allows displaying numarray images to DS9 and related image display programs (google numdisplay). But if you are hoping to combine matplotlib features with image display, this isn't going to help much. But if you are looking mainly to use DS9 or ximtool features, you can just use them directly and save yourself the trouble of trying to emulate them (not that wouldn't be a nice thing to have for matplotlib).

Perry

···

On Dec 20, 2004, at 3:55 AM, Eric Emsellem wrote: