Hi Frederik, Thanks for the help. I'll see if I can utilize the palette as you describe. If I can craft a good noise detection algorithm, I'll post my code back to the SIG.
Best Regards, J.D. On Sat, Apr 18, 2009 at 4:54 PM, J.D. Main <jdm...@comcast.net> wrote: > Here's a URL explaining all this: http://radar.weather.gov/GIS.html > > In short these images are GIF files with a 256 color pallete. The > "interesting" pixels in these images are red, green, yellow and blue. > > The pixels representing radar "noise" usually appear as brown, grey, and > purple. > > My desire is to iterate over all pixels and remove the noise. The pseudo > code would look something like this: > > for pixel in radar_image: > if pixel is noise: > turn pixel white > else: > do nothing > > I'm having a hard time with this. Can anyone provide some insight into a > method? It would be greatly appreciated. Given that GIF images are 8-bit images with a color palette (that is, the pixel values are indexes into a color palette), here's a better outline: im = Image.open("radar-image.gif") palette = im.getpalette() # prepare lookup table lut = range(256) for i in range(256): r, g, b = palette[i*3:i*3+3] if is_noise(r, g, b): lut[i] = 0 # or whatever index you want for the background # map all noise colors to 0, leave rest as is im = im.point(lut) The getpalette function returns the color palette as a 768-item list containing [red0, green0, blue0, red1, green1, ...]. The is_noise function checks if the given RGB value corresponds to a noise color (you have to write this one yourself). Note that if the "noise" colors occupy a given index range, you can skip the palette test and just set lut[i] to the background index if i is in that range. </F> _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig