mike chambers | about

Pixel Bender Grayscale Filter

Below is another simple Pixel Bender filter that I created last night. This one basically, converts an image to gray scale, using the ITU-R Recommendation BT.709 algorithm described here.

Here is the filter:

<languageVersion : 1.0;>

kernel GrayScale
<   namespace : "mesh";
    vendor : "Mike Chambers";
    version : 1;
    description : "Gray scale filter";
>
{
    input image4 src;
    output pixel4 dst;

    void
    evaluatePixel()
    {
        dst = sampleNearest(src,outCoord());

        //algorithm from ITU-R Recommendation BT.709
        //http://local.wasp.uwa.edu.au/~pbourke/texture_colour/imageprocess/
        float avg = 0.2125 * dst.r + 0.7154 * dst.g + 0.0721 * dst.b;
        dst = float4(avg, avg, avg, dst.a);

    }
}

Again, its pretty simple, but I am trying to learn both Pixel Bender and image processing in general. The biggest thing I learned for this example is how to work with different vector sizes (which can be a little confusing). Im still wrapping my head around it, but once I get it down, Ill make a post on vectors in Pixel Bender.

Tags:
twitter github flickr behance