[Image-SIG] Low level access

James Shuttleworth csx239@coventry.ac.uk
Thu, 11 Jul 2002 18:12:17 +0100


I thought about doing this, but (as far as I know) point only evaluates o=
nce=20
for each pixel value, so there's no way to use another image as a source.=
 =20
Plus the function passed to it can only take one parameter (and I'd need =
to=20
know coordinates as well as the value).  Ah well.  Someone has suggested=20
using numeric, so I'll try that and see what happens.

Thanks for replying,

James

On Thursday 11 Jul 2002 4:07 pm, Robert Klimek wrote:
> 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.=
=20
> > 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 t=
he
> > pixel info from the two files.  What I then wanted to do was to remov=
e
> > the use of putpixel.  First I thought I'd use getdata to get an objec=
t 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 rath=
er
> > 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 th=
e
> > job? It's taking around 23s per image pair, which is just too slow.=20
> > 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 al=
l
> 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=3D128):
>     # set to 255 if pixel greater than value
>     t =3D image.point(lambda i, v=3Dvalue: i > v and 255)
>     return t
>
>
> Maybe you can modify it to suit your requirement? However, there are ma=
ny
> situations where I don't know how to implement this scheme, such as the=
 one
> you're requesting.
>
> Hope this helps!
> Bob
>
>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig