David Berthelot wrote:
What I do is that I use numpy arrays to store images and perform all my math 
stuff on them.

numpy is good for this stuff, particularly if it gets more complicated,
but a few comments"

Example:
import Image
import numpy as N
f = Image.open("image.gif")
g = N.array(N.asarray(f))

note: numpy.asarray returns a read-only array, so calling array() on it
makes a copy, so that you can change it. You could use
N.asarray(f).copy() as well.

Since these are 8-bit palleted images, what you get is a uint8 array,
not an rbg array.

for y in xrange(g.shape[0]):
  for x in xrange(g.shape[1]):

the glory (or, one of the glories) or numpy is that you don't have to
loop, you can operate in the whole array as a unit.

As Fredrik said, You'd have to look at the Pallet to see which color is
which, but you can do:

noise_color = 4
white = 0
g[g == noise_color] = white

and presto -- every noise pixel is now white.

Enclosed is a test script that demos some of this.

By the way, I tried setting the palette of the new image like so:

im2.putpalette(im.palette)

and it mostly worked, but white can turned into magenta -- can anyone
tell me why/

Also, the new gif is twice as big as the old -- is it not compressed the
same way?

-Chris



--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov

Attachment: test_gif.py
Description: application/python

_______________________________________________
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to