speeding up imshow

Hello,
I want to use imshow to make a real time waterfall plot. The attached
code is the core of my application, and it works, but it is quite
slow, around 200ms to update the plot. Is there a way to accelerate
this? I have seen the blitting demos, and they work well for the line
plots, but I could not figure out how to extend this functionality to
imshow plots. In theory I could throw all of my data into a bitmap
(since I don't really need the antialiasing etc provided by AGG) and
display that directly in WX, but the trouble with that is I want to
display the spectra at a given time and the waterfall plot with the
same X axis, thus computing the area to display the bitmap seems
tricky. Is there any built in MPL functionality for doing that?
One question about the blitting demos: they do not seem to work well
with resizing the window (which make sense because the blit buffer
never gets informed of the window size change). Has anyone modified
this code to allow it to work with resizing? I tried to connect to the
RESIZE event and recapture the base canvas, but did not have any luck.
Thanks,
Glenn

imshowtest.py (3.97 KB)

gui.py (4.17 KB)

I just use blit on imshow map, and work properly. Maybe the following code
will help you.

def ontimer()
       canvas.restore_region(background)
       im.set_array(Z)
       ax.draw_artist(self.imList[i])
       canvas.blit(ax.bbox)
       canvas.gui_repaint()

···

--
View this message in context: http://www.nabble.com/speeding-up-imshow-tp16623430p16656693.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Thank you for the suggestion.
I now have the update time down to about 70 ms.
When I run the code through the profiler, I see that each plot update
requires a call to matplotlib.colors.Colormap.__call__, and each of
these calls takes 52 ms, 48 ms of which is spent inside the function
itself. This looks like it is the bulk of the delay, so if I can
optimize the Colormap.__call__ function, the performance should be
much improved. Unfortunately I cannot seem to get finer grained
information about what exactly is taking so long inside this function.
Can anyone provide any hints?
Thanks,
Glenn

···

On Sat, Apr 12, 2008 at 7:02 PM, hjc520070 <jiacong_huang@...1221...> wrote:

I just use blit on imshow map, and work properly. Maybe the following code
will help you.

def ontimer()
       canvas.restore_region(background)
       im.set_array(Z)
       ax.draw_artist(self.imList[i])
       canvas.blit(ax.bbox)
       canvas.gui_repaint()
--
View this message in context: http://www.nabble.com/speeding-up-imshow-tp16623430p16656693.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Glenn,

What version of numpy are you using? What version of matplotlib? And what are the dimensions of your image array?

Eric

G Jones wrote:

···

Thank you for the suggestion.
I now have the update time down to about 70 ms.
When I run the code through the profiler, I see that each plot update
requires a call to matplotlib.colors.Colormap.__call__, and each of
these calls takes 52 ms, 48 ms of which is spent inside the function
itself. This looks like it is the bulk of the delay, so if I can
optimize the Colormap.__call__ function, the performance should be
much improved. Unfortunately I cannot seem to get finer grained
information about what exactly is taking so long inside this function.
Can anyone provide any hints?
Thanks,
Glenn

On Sat, Apr 12, 2008 at 7:02 PM, hjc520070 <jiacong_huang@...1221...> wrote:

I just use blit on imshow map, and work properly. Maybe the following code
will help you.

def ontimer()
       canvas.restore_region(background)
       im.set_array(Z)
       ax.draw_artist(self.imList[i])
       canvas.blit(ax.bbox)
       canvas.gui_repaint()
--
View this message in context: http://www.nabble.com/speeding-up-imshow-tp16623430p16656693.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Numpy 1.0.3 and MPL 0.91.2. The image array is 256 x 1024. I found I
could speed things up a lot (~15ms update time) by setting my data to
be a 256 x 1024 x 4 array of uint8, so I guess the solution is to
handle color mapping myself. I appreciate any other suggestions.
Glenn

···

On 4/15/08, Eric Firing <efiring@...202...> wrote:

Glenn,

What version of numpy are you using? What version of matplotlib? And what
are the dimensions of your image array?

Eric

G Jones wrote:

> Thank you for the suggestion.
> I now have the update time down to about 70 ms.
> When I run the code through the profiler, I see that each plot update
> requires a call to matplotlib.colors.Colormap.__call__,
and each of
> these calls takes 52 ms, 48 ms of which is spent inside the function
> itself. This looks like it is the bulk of the delay, so if I can
> optimize the Colormap.__call__ function, the performance should be
> much improved. Unfortunately I cannot seem to get finer grained
> information about what exactly is taking so long inside this function.
> Can anyone provide any hints?
> Thanks,
> Glenn
>
> On Sat, Apr 12, 2008 at 7:02 PM, hjc520070 <jiacong_huang@...1221...> wrote:
>
> > I just use blit on imshow map, and work properly. Maybe the following
code
> > will help you.
> >
> > def ontimer()
> > canvas.restore_region(background)
> > im.set_array(Z)
> > ax.draw_artist(self.imList[i])
> > canvas.blit(ax.bbox)
> > canvas.gui_repaint()
> > --
> > View this message in context:
http://www.nabble.com/speeding-up-imshow-tp16623430p16656693.html
> > Sent from the matplotlib - users mailing list archive at Nabble.com.
> >
>

Glenn,

The slowness is almost entirely in the line

    rgba = lut[xa]

where lut is a 2-D uint8 table and xa is an array of indices.

I have replaced that in svn with

    rgba = lut.take(xa, axis=0)

which cuts the time in half!

That is still not nearly as fast as the solution you have found. It should be possible to approach it by putting in a little extension code that optimizes the body of the __call__ method. And for me at least, that would be easiest to do with pyrex. Until a decision is made to use pyrex/cython in core matplotlib, however, this will have to wait.

Another approach would be to look for ways to speed up fancy indexing in numpy. That would probably be very difficult, but could also be very rewarding if successful.

Eric

G Jones wrote:

···

Numpy 1.0.3 and MPL 0.91.2. The image array is 256 x 1024. I found I
could speed things up a lot (~15ms update time) by setting my data to
be a 256 x 1024 x 4 array of uint8, so I guess the solution is to
handle color mapping myself. I appreciate any other suggestions.
Glenn

On 4/15/08, Eric Firing <efiring@...202...> wrote:

Glenn,

What version of numpy are you using? What version of matplotlib? And what
are the dimensions of your image array?

Eric

G Jones wrote:

Thank you for the suggestion.
I now have the update time down to about 70 ms.
When I run the code through the profiler, I see that each plot update
requires a call to matplotlib.colors.Colormap.__call__,

and each of

these calls takes 52 ms, 48 ms of which is spent inside the function
itself. This looks like it is the bulk of the delay, so if I can
optimize the Colormap.__call__ function, the performance should be
much improved. Unfortunately I cannot seem to get finer grained
information about what exactly is taking so long inside this function.
Can anyone provide any hints?
Thanks,
Glenn

On Sat, Apr 12, 2008 at 7:02 PM, hjc520070 <jiacong_huang@...1221...> wrote:

I just use blit on imshow map, and work properly. Maybe the following

code

will help you.

def ontimer()
      canvas.restore_region(background)
      im.set_array(Z)
      ax.draw_artist(self.imList[i])
      canvas.blit(ax.bbox)
      canvas.gui_repaint()
--
View this message in context:

http://www.nabble.com/speeding-up-imshow-tp16623430p16656693.html

Sent from the matplotlib - users mailing list archive at Nabble.com.

Eric Firing wrote:

Glenn,

The slowness is almost entirely in the line

    rgba = lut[xa]

where lut is a 2-D uint8 table and xa is an array of indices.

I have replaced that in svn with

    rgba = lut.take(xa, axis=0)

which cuts the time in half!

This should be reduced by another factor of 1/2 to 1/3 if you use numpy svn as of this morning. The take method got a speedup treatment. I would be interested to know how it works now in your application. It may still be quite a bit slower than the solution you settled on.

Eric