[Numpy-discussion] collecting the bluest pixels

Stéfan van der Walt stefan@sun.ac...
Tue Oct 7 14:28:46 CDT 2008

Hi Paul

2008/10/7 paul taney <paultaney@yahoo.com>:
> I have this silly color filter that Stefan gave me:
> def vanderwalt(image, f):
>    """colorfilter, thanks to Stefan van der Walt"""
>    RED, GRN, BLU = 0, 1, 2
>    bluemask = (image[...,BLU] > f*image[...,GRN]) & \
>               (image[...,BLU] > f*image[...,RED])
>    return bluemask

Here's a heuristic method that may work.  The above statement is equivalent to

image[...,BLU] > f*max(image[...,GRN], image[...,RED])

So I would construct a new array with the maximum of the red and green
values.  Then, divide that new image by the blue image -- this gives
you all the different "f" values above.  Calculate the histogram of
the "f"s, and pick an f with the right percentile.


More information about the Numpy-discussion mailing list