Um die Arbeitsweise mit Pixel Bender (ehemals Hydra) auszuprobieren, habe ich einen Filter geschrieben, der in Echtzeit ein Green-Screen-Video filtert. Über einen Threshold-Regler lässt sich die Stärke des Filters regeln. Über drei Slider (RGB-Farbwert) kann die Keyfarbe festgelegt werden.
Hier das Beispiel zum Anschauen: Demo
Hinweis: Um das Beispiel zu betrachten, wird der Flash Player 10 (zurzeit in der Betaphase) benötigt.
Pixel Bender Colorkey Filter
Der Colorkey-Filter hat eine RGB-Farbe als Grundlage, also die Keyfarbe. Alle Werte, die dieser Farbe exakt entsprechen werden transparent gemacht. Des Weiteren werden alle ähnlichen Farben unsichtbar gemacht, wobei die Toleranz über den „Threshold“ genauer geregelt werden kann.
Mit weiteren Bearbeitungsschritten wie Kantenglättung, etc. würde sich die Qualität des Filters sicherlich um einiges optimieren lassen. Außerdem ist das Grün im Beispielvideo relativ dunkel und wäre bei gutem Footage wesentlich besser zu filtern.
Der Filtercode für Pixel Bender lautet:
[code]
/*****************************************************************************
*
* by Florian Plag
* www.video-flash.de
*
*****************************************************************************/
// color keying
kernel colorKey
< namespace : "AIF";
vendor : "Florian Plag";
version : 1;
description : "Color keying"; >
{
input image4 src;
output float4 dst;
// Threshold
parameter float threshold
// key color (RGB)
parameter float3 keyColor;
void
evaluatePixel()
{
// Obtain the input pixel color
float4 inputColor = sampleNearest(src, outCoord());
// tolerance for key color
float3 keyCMinusThr = float3 ( (keyColor.r – threshold), (keyColor.g – threshold), (keyColor.b – threshold));
float3 keyCPlusThr = float3 ( (keyColor.r + threshold), (keyColor.g + threshold), (keyColor.b + threshold));
// if color is the key color (or similar)
if ( ((inputColor.r > keyCMinusThr.r) && (inputColor.r < keyCPlusThr.r)) && ((inputColor.g > keyCMinusThr.g) && (inputColor.g < keyCPlusThr.g)) && ((inputColor.b > keyCMinusThr.b) && (inputColor.b < keyCPlusThr.b)) ) {
// transparent pixel
dst.rgba = float4(1.0, 1.0, 0.0, 0.0);
}
else {
// keep source pixel
dst.rgb = inputColor.rgb;
// and source alpha
dst.a = inputColor.a;
}
}
}
[/code]
Wie nutzt man Pixel Bender in Flash/Flex?
Anhand des Beispiels sieht man, wie man einen Pixel Bender Filter in Flex verwendet.
[xml]
[/xml]
[ad]
Link: Beispiel anschauen
WOW! Gute Arbeit!
Die Demo funktioniert leider nicht.
Hast du die Flash Player 10 Beta installiert? Bei mir funktioniert es :-)
wow! Impressed nice one
Nice filter, impressive! I have made a pixel bender filter that changes the individual RGB color channels to any given color. This way you can set a picture to match a given set of colors. You can try it out and download it at http://last.instinct.se/graphics-and-effects/channel-colorizer-demo-application/554
Keep up the good work!
/Klas
Good god this is beautiful, you have saved me!