Best way to cycle through numpy images

Best way to cycle through numpy images
Sorry if this get’s re-posted, my earlier e-mail didn’t seem to go through.

I have an array of images stored as an array of numpy arrays. I need to be able to efficiently scroll through that set of images. My first attempt at doing this goes something like this:

–init–

    self.ax = pyplot.imshow(imgdta[0], interpolation='spline36', cmap=cm.gray, picker=True)      # draw the plot @UndefinedVariable

    pyplot.axes().set_axis_off()

    self.fig = self.ax.get_figure()

    self.canvas = FigureCanvasGTKAgg(self.fig)   

–onscroll–

    self.ax.set_array(imdta[n]) # 0 < n < num_images

    self.canvas.draw()

This method ends up re-interpolating the image on each scroll event (which takes SIGNIFICANT time). What I’d like to do is pre-build the images and then just change what image is displayed on the canvas on each scroll event. I cannot seem to figure out how to do this. Can anybody give me a pointer in the right direction.

Thanks,

Dave.

You are doing it how I would do it for animations of imshow, which does not result in re-interpolations. I wonder if the on_scroll event is getting called more often than it needs? How big are these images?

Ben Root

···

On Thu, Aug 11, 2011 at 11:19 AM, David Just <Just.David@…3721…> wrote:

Sorry if this get’s re-posted, my earlier e-mail didn’t seem to go through.

I have an array of images stored as an array of numpy arrays. I need to be able to efficiently scroll through that set of images. My first attempt at doing this goes something like this:

–init–

    [self.ax](http://self.ax) = pyplot.imshow(imgdta[0], interpolation='spline36', cmap=cm.gray, picker=True)      # draw the plot @UndefinedVariable

    pyplot.axes().set_axis_off()

    self.fig = self.ax.get_figure()

    self.canvas = FigureCanvasGTKAgg(self.fig)   

–onscroll–

    self.ax.set_array(imdta[n]) # 0 < n < num_images

    self.canvas.draw()

This method ends up re-interpolating the image on each scroll event (which takes SIGNIFICANT time). What I’d like to do is pre-build the images and then just change what image is displayed on the canvas on each scroll event. I cannot seem to figure out how to do this. Can anybody give me a pointer in the right direction.

Thanks,

Dave.

Benjamin Root, on 2011-08-11 11:25, wrote:

···

On Thu, Aug 11, 2011 at 11:19 AM, David Just <Just.David@...3721...> wrote:
> --onscroll--
> self.ax.set_array(imdta[n]) # 0 < n < num_images
> self.canvas.draw()

You last line here causes every artist on the canvas to draw.

Have you tried blitting just the relevant axis? Look at the
blitting animation examples (on the site) which have moved to
examples/animation/old_animation in git.

best,
--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7