[Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif)

Christopher Barker Chris.Barker at noaa.gov
Tue Apr 21 01:34:02 CEST 2009

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:


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?


Christopher Barker, Ph.D.

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.Barker at noaa.gov

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_gif.py
Type: application/x-python
Size: 1033 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090420/56364e4d/attachment.bin>

More information about the Image-SIG mailing list