PhotoImage.paste

rryan.asu at gmail.com rryan.asu at gmail.com
Tue Jan 24 14:40:14 EST 2017


Hi Peter,

Yes, that was the first thing I did, even before using the paste method.  I read the warning on effbot and other sites, and simply coded it up as

new_image.putpalette(palette)
photo=ImageTk.PhotoImage(image=new_image)
canvas_object=canvas.create_iamge(x,y,image=photo)

And this was a small bit faster, but still quite slow (say 0.1 s).  So just to understand the warning on effbot, I tried using paste, where'd I just do something like

image.putpalette(palette)
photo.paste(image)

and that took about 0.15 s. But my canvas has a few other things displayed on it, so each time that you create a new image/canvas object, I still have to run the lift method to order the items appropriately.  So all in all, the new image method wasn't that much better --- and ultimately still too slow for my interest.  

It seems that for some reason PIL just has this a limitation, which is really sad.  I think I can skirt the issue by when you start the mouse action, grab the bounding box from the view and only apply the new palette math to that subregion.  Then when the mouse action is finished, load the palette to the entire image with paste, and accept the time is 0.15 sec --- but this is not done in "real time".  This is will be a substantial amount of coding and quite ugly.  I'm just surprised that this is so clunky. 

Thanks for the suggestion.
Russell




On Tuesday, January 24, 2017 at 11:59:49 AM UTC-5, Peter Otten wrote:
>@gmail.com wrote:
> 
> > I'm trying to build a tkinter GUI with python 3.5, and would like to
> > interactively adjust the color palette for an image by moving the mouse in
> > the canvas using PIL.  In pseudo-code, I have something like
> > 
> > palette=color_map(x,y)   # x,y are scalars indicating the position of the
> > mouse in the Canvas image.putpalette(palette)
> > photo.paste(image)
> > 
> > This works just fine, but is very slow.  The photo.paste(image) step takes
> > about 0.15 s (using an image that is 4k x 4k).  I read the manual on
> > effbot, and they caution that the paste method would be slow if the image
> > is display --- and I'm guessing that's what I'm doing.
> 
> So you have read
> 
> """
> Note: Pasting into an RGBA image that is displayed is a very slow operation. 
> It’s usually better to create a new image object.
> """
> 
> on <http://effbot.org/imagingbook/imagetk.htm>.
> 
> > So my question is, what alternatives do I have to speed that step up.
> 
> Did you try to create a new image, as the note suggests?
> 
> > Thank you for any thoughts you might have...
> > -Russell


More information about the Python-list mailing list