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.
<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.







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
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
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
I was under the impression that the Flash Pixel Bender implementation was 100% software based?
kode80
19 Sep 08 at 12:53 pm
@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
Cool
saeed ashour
21 Sep 08 at 1:40 pm
[...] Chambers ???????????????????????????????????? [...]
Pixel Bender ?2?? ?? lineTo ????????????????? | Yellow Soup
31 Oct 08 at 12:13 pm
[...] [...]
Anonymous
12 Jan 10 at 5:29 am