[Numpy-discussion] color filtering
Stéfan van der Walt
stefan at sun.ac.za
Wed Sep 17 12:37:53 EDT 2008
Hey Paul
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
2008/9/17 paul taney <paultaney at yahoo.com>:
> I need to do a color filter; I have it working in python
> but it runs forever on some of my images. And I dont know
> enuf c or c++ to use weave (or Boost or Pyrex or...)
> # But while testing we can use:
>
> import numpy as np
> a = np.array(
> [[[ 64, 237, 108], # x y
> [185, 240, 68], # [0, 1]
> [ 17, 116, 55], # [0, 2]
> [107, 11, 185], # [0, 3] is blue
> [154, 30, 52]], # [0, 4]
>
> [[251, 73, 150], # x y
> [ 47, 225, 97], # [1, 1]
> [101, 91, 251], # [1, 2] is blue
> [ 61, 23, 79], # [1, 3]
> [161, 22, 165]], # [1, 4]
>
> [[ 4, 162, 188], # [2, 0]
> [ 25, 131, 211], # [2, 1]
> [162, 112, 177], # [2, 2]
> [169, 83, 214], # [2, 3] is blue
> [254, 139, 95]],
>
> [[ 2, 88, 216], # [3, 0] is blue
> [230, 63, 192],
> [ 71, 78, 250], # [3, 2] is blue
> [113, 151, 142],
> [104, 65, 127]],
>
> [[ 6, 191, 220], # [4, 0] is blue
> [ 38, 141, 4],
> [245, 41, 23],
> [ 23, 127, 183], # [4,] is blue
> [165, 24, 5]]], np.uint8)
More information about the NumPy-Discussion
mailing list