8

Pixel Bender Grayscale Filter

 3 years ago
source link: http://www.mikechambers.com/blog/2008/09/18/pixel-bender-grayscale-filter/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Pixel Bender Grayscale Filter

Thursday, September 18, 2008

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.

Pixel Bender Grayscale Filter

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK