Mike Chambers

code = joy

Pixel Bender Grayscale Filter

with 9 comments

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.

Written by mikechambers

September 18th, 2008 at 8:38 am

Posted in General

Tagged with

9 Responses to 'Pixel Bender Grayscale Filter'

Subscribe to comments with RSS or TrackBack to 'Pixel Bender Grayscale Filter'.

  1. Cool… once I REALLY figure out pixelbender I’ll probably agree this is “simple”. I’m just over “learning” color matrixes… like this grayscale:

    import flash.filters.ColorMatrixFilter;
    var cm:ColorMatrixFilter = new ColorMatrixFilter();

    cm.matrix = new Array(
    0.3086, 0.609, 0.282, 0, 0,
    0.3086, 0.609, 0.282, 0, 0,
    0.3086, 0.609, 0.282, 0, 0,
    0, 0, 0, 1, 0);

    someClip.filters = [cm];

    Phillip Kerman

    18 Sep 08 at 8:46 am

  2. Does this render faster or slower than other ways of desaturating an image, e.g. using a ColorMatrixFilter?

    Iain

    19 Sep 08 at 1:58 am

  3. Iain,

    That is a good question. In optimum circumstances, I think it would be significantly faster as it can take advantage of hardware / GPU acceleration to perform the transformation.

    However, i am not sure what the difference would be on a normal sized image. I might try and do some tests later today (and I post them here or in a seperate post).

    mike chambers

    mesh@adobe.com

    mikechambers

    19 Sep 08 at 8:49 am

  4. I was under the impression that the Flash Pixel Bender implementation was 100% software based?

    kode80

    19 Sep 08 at 12:53 pm

  5. @kode80

    Yes, you are correct. (thats what I get for picking up Pixel Bender for the first time in a long time, and not get up to speed on all of the changes).

    However, Pixel Bender filters are still multi-threaded in the Flash Player, so, especially on larger images, that could lead to a significant boost.

    Check out tinic’s post for more info:

    http://www.kaourantin.net/2008/05/adobe-pixel-bender-in-flash-player-10.html

    I am going to put together a simple example shortly to test the differences in speed.

    mike chambers

    mesh@adobe.com

    mikechambers

    19 Sep 08 at 2:41 pm

  6. Cool

    saeed ashour

    21 Sep 08 at 1:40 pm

  7. [...] Chambers ???????????????????????????????????? [...]

  8. [...] [...]

    Anonymous

    12 Jan 10 at 5:29 am

  9. Hi Mike,

    Have you ever tried implementing this into slideshowpro and Thumbgrid when you are using a layered approach like their demo here: http://slideshowpro.net/demo/ThumbGrid-Layer-Demo/

    I keep getting blank screens – have emailed SSP support as well… Any advice is much appreciated – THANKS!

    kyle

    26 Aug 10 at 9:03 am

Leave a Reply

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: