[Numpy-discussion] Using where with tuples

Nadav Horesh nadavh@visionsense....
Sat Apr 11 13:03:28 CDT 2009


b = a2.copy()
base256 = 256**arange(4)
idx = dot(a2, base256)
from = dot((255,0,0,255), base256)
to = dot((0,0,0,255), base256)
b[idx == from] = to

Nadav
-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Frank Peacock
נשלח: ש 11-אפריל-09 02:28
אל: numpy-discussion@scipy.org
נושא: [Numpy-discussion] Using where with tuples
 
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 --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3127 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090411/28b468be/attachment.bin 


More information about the Numpy-discussion mailing list