[Numpy-discussion] color filtering

paul taney paultaney@yahoo....
Wed Sep 17 15:33:26 CDT 2008



> coords were tossed.
> > Can you show me a cheap way to return a line:
> >
> >    line=[(3, 0), (2, 1), (0, 2), (1, 2), (3, 2), (0,
> 3), (4, 3), (3, 4)]
> >
> > type-o-thing?
> 
> Sure, how about
> 
> np.array(bluemask.nonzero()).swapaxes(0,1)
> 
> Does that do what you want?

Exactly.  Very cool stuff.  Thanks alot!
    
RED, GRN, BLU = 0, 1, 2
def test8(a, f):
    bluemask = (a[...,BLU] > f*a[...,GRN]) & \
               (a[...,BLU] > f*a[...,RED])
    print "test 8 with factor=%f" % f
    return np.array(bluemask.nonzero()).swapaxes(0,1)

print test8(a, 1.4)

test 8 with factor=1.400000
[[0 3]
 [1 2]
 [2 1]
 [3 0]
 [3 4]
 [4 3]]


paul 





More information about the Numpy-discussion mailing list