[Numpy-discussion] color filtering
paul taney
paultaney at yahoo.com
Wed Sep 17 14:20:03 EDT 2008
> Maybe this helps:
>
> # silly algorithm for guessing blue pixels
> >>> bluemask = (a[...,2] > 1.25*a[...,1]) & (a[...,2] > 1.25*a[...,0])
>
> >>> a[bluemask, :]
> array([[107, 11, 185],
> [101, 91, 251],
> [ 61, 23, 79],
> [ 25, 131, 211],
> [169, 83, 214],
> [ 2, 88, 216],
> [ 71, 78, 250],
> [ 23, 127, 183]], dtype=uint8)
>
> Cheers
> Stéfan
Thanks Stéfan, that"s very cool. But the xy 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?
I think I decyphered the boolean array I was getting from
def test5(a, THRESH):
RED, GRN, BLU = 0, 1, 2
line_pix = ((a[:, :, RED] <= THRESH) &
(a[:, :, GRN] <= THRESH) &
(a[:, :, BLU] >= THRESH))
print "test5: line_pix = %r" % (line_pix)
return line_pix
#test5: line_pix = array(
# x=0 1 2 3 4
# y=0 [[False, False, False, True, False], # [3, 0] is blue
# 1 [False, False, True, False, False], # [2, 1] is blue
# 2 [ True, True, False, True, False], # [0, 2] xxx, [1, 2] is blue, [3, 2] xxx
# 3 [ True, False, False, True, False], # [0, 3] is blue, [4, 3]
# 4 [False, False, False, True, False]]) # [3, 4] is blue
# So now I have to fawn over it for the coords. Is there a cheaper way?
def dump_bool_array(b):
very_blue_pixels = []
w = DIM[0]
x = y = 0
for xyslice in b:
for bool in xyslice:
if bool:
very_blue_pixels.append((x, y))
x += 1
if x==w: x=0
y += 1
print "dump_bool_array=%r" % (very_blue_pixels)
# [(3, 0), (2, 1), (0, 2), (1, 2), (3, 2), (0, 3), (4, 3), (3, 4)]
THrow away the other attachment. It had a very bad bug, swapping
x and y. Ug.
paul
----
def test7(a, fact):
RED, GRN, BLU = 0, 1, 2
bluemask = (a[...,BLU] > fact*a[...,GRN]) & \
(a[...,BLU] > fact*a[...,RED])
b = a[bluemask, :]
print "test 7 with factor=%f" % fact
return b
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_minmax.py
Type: application/octet-stream
Size: 6947 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080917/622fbe73/attachment.obj>
More information about the NumPy-Discussion
mailing list