[Image-SIG] Re: Low level access

John Lockwood jal@cinesite.co.uk
Thu, 11 Jul 2002 17:24:52 +0100


Using numerical python might be faster for you.

Use the tostring and fromstring fuction in both packages to convert from one to
the other.


http://www.pfdubois.com/numpy/

jal






image-sig-request@python.org wrote:

> Send Image-SIG mailing list submissions to
>         image-sig@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.python.org/mailman/listinfo/image-sig
> or, via email, send a message with subject or body 'help' to
>         image-sig-request@python.org
>
> You can reach the person managing the list at
>         image-sig-admin@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Image-SIG digest..."
>
>   ------------------------------------------------------------------------
> Today's Topics:
>
>    1. Re: Low level access (Robert Klimek)
>
>   ------------------------------------------------------------------------
>
> Subject: Re: [Image-SIG] Low level access
> Date: Thu, 11 Jul 2002 11:07:51 -0400
> From: Robert Klimek <klimek@grc.nasa.gov>
> To: James Shuttleworth <csx239@coventry.ac.uk>
> CC: "mailing List (PIL)" <image-sig@python.org>
> References: <200207101605.49647.csx239@coventry.ac.uk>
>
> On Wednesday 10 July 2002 11:05 am, you wrote:
> > Hi,
> >   I've just been playing with the PIL and I'm quite impressed.  It's my
> > first use of python, so I've been having lots of fun.  I do have a question
> > though...
> >
> > I've been writing a tool that alters an image based on the content of
> > another. The first way I tried it, I hust used getpixel and putpixel.  This
> > worked fine, but it was very very slow.  I speeded things up a little
> > (actually, I doubled the speed) by using getdata to retrieve the pixel info
> > from the two files.  What I then wanted to do was to remove the use of
> > putpixel.  First I thought I'd use getdata to get an object of the right
> > size and then alter it for the new image, but I can't (it's immutable?).
> > Is there any way to quickly manipulate the image data at the pixel level?
> > I've been using the fromstring method to speed things up a little (creating
> > a list and then joining it to create the string rather than using
> > concatenation), but it's hardly a big improvement.
> >
> > Am I going about this in the wrong way?  Is PIL the right tool for the job?
> > It's taking around 23s per image pair, which is just too slow.  Ideally,
> > this is intended for frame by frame compositing of rendered movie passes.
> >
> > Any ideas?
> >
>
> I'm often frustrated by this as well, where you need to loop through all the
> pixels of an image and perform some operation, like on a 3x3 neighborhood.
> I'm currently looking at a floodfill operation and I'm running into the speed
> problem. The one thing in PIL that is very fast is the point() function. It
> may be coupled with lambda such as this simple threshold operation below:
>
> def Threshold(image, value=128):
>     # set to 255 if pixel greater than value
>     t = image.point(lambda i, v=value: i > v and 255)
>     return t
>
> Maybe you can modify it to suit your requirement? However, there are many
> situations where I don't know how to implement this scheme, such as the one
> you're requesting.
>
> Hope this helps!
> Bob