[Numpy-discussion] Using where with tuples

Frank Peacock frank at gis4weather.com
Fri Apr 10 20:28:13 EDT 2009


Hello

 

I am trying to use the where function on a numpy array which was obtained
from an image using the asarray function. The code is as follows:

 

from numpy import *

from Image import *

im=open("a.gif")

im2=im.convert("RGBA")

a2 = asarray(im2,uint8)

c = zeros((140,90,4),uint8)

c[:,:] = [0,0,0,255]

b=where(a2[:,:]==(255,0,0,255),c,a2)

c=fromarray(b,"RGBA")

c.save("c.gif")

 

I am trying to convert only red colours to black but although this works it
also converts other tuples as well. How do I ensure that the tuple condition
is enforced exactly, i.e. only on red colours?

 

Thanks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090411/d3dd5b95/attachment.html>


More information about the NumPy-Discussion mailing list