<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Andy Li’s Blog - Pixel Bender</title><link href="https://blog.onthewings.net/" rel="alternate"></link><link href="http://feeds.feedburner.com/tag/pixel-bender/feed/atom.xml" rel="self"></link><id>https://blog.onthewings.net/</id><updated>2010-02-19T20:55:00+08:00</updated><entry><title>Colorblink - An AIR app that simulates how color blind people see Flash and images</title><link href="https://blog.onthewings.net/2010/02/19/colorblink-an-air-app-that-simulates-how-color-blind-people-see-flash-and-images/" rel="alternate"></link><published>2010-02-19T20:55:00+08:00</published><updated>2010-02-19T20:55:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2010-02-19:/2010/02/19/colorblink-an-air-app-that-simulates-how-color-blind-people-see-flash-and-images/</id><summary type="html">&lt;p&gt;&lt;img alt="Select color blind type from the menu." src="/files/2010/colorblink-demo.png"/&gt;&lt;/p&gt;
&lt;p&gt;Accessibility is a an important part of both web and game design. And
for web and game design, one of the popular tool is Flash. That means
very often you need to ensure accessibility in Flash. However there are
still not many tools available even for simple things like color …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="Select color blind type from the menu." src="/files/2010/colorblink-demo.png"/&gt;&lt;/p&gt;
&lt;p&gt;Accessibility is a an important part of both web and game design. And
for web and game design, one of the popular tool is Flash. That means
very often you need to ensure accessibility in Flash. However there are
still not many tools available even for simple things like color blind
simulation… so I write my own:)&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; &lt;a href="http://github.com/andyli/Colorblink/raw/master/Colorblink.air"&gt;download installer (.air)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It’s a very simple &lt;span class="caps"&gt;AIR&lt;/span&gt; app. You open it, drop a swf file on its window,
select the color blind type and that’s it.&lt;/p&gt;
&lt;p&gt;The inner of Colorblink is using a Pixel Bender filter, applying to the
whole application. The algorithm is just a color transform matrix, found
in &lt;a href="http://homepage.mac.com/lpetrich/ColorBlindnessSim/ColorBlindnessSim.html"&gt;a Java Color-Blindness Simulators&lt;/a&gt;. That simulator have more
simulation config, which I used only the simplest one.&lt;/p&gt;
&lt;p&gt;This is also my first time using a git repo. So &lt;a href="http://github.com/andyli/Colorblink"&gt;go to have a look&lt;/a&gt;,
see if you can fork it for more features.&lt;/p&gt;
&lt;p&gt;&lt;del&gt;One thing is, there is
problem loading Flex applications into Colorblink… I don’t know how to
read the loaded app’s default width and height and then resize it… So,
if you want to test your Flex app, &lt;a href="http://github.com/andyli/Colorblink/tree/master/src/net/onthewings/filters/"&gt;get the filter&lt;/a&gt; and apply it to
your app manually (can’t be easier).&lt;/del&gt;&lt;br/&gt;
Now you can load Flex swf or even html file! But the app wouldn’t
resize automatically since the size cannot be determined. If Colorblink
does not work for you, you can still always &lt;a href="http://github.com/andyli/Colorblink/tree/master/src/net/onthewings/filters/"&gt;get the filter&lt;/a&gt; and apply
it to your app manually (can’t be easier).&lt;/p&gt;
&lt;p&gt;Oh, yes, there is a simulation of what a dog sees… So, design some
game for your dogs in your free time…&lt;/p&gt;</content><category term="Flash"></category><category term="Flex"></category><category term="Pixel Bender"></category><category term="web usability design and engineering"></category></entry><entry><title>Chroma key and thresholding in Flash (Pixel Bender), revised</title><link href="https://blog.onthewings.net/2009/12/10/chroma-key-and-thresholding-in-flash-pixel-bender-revised/" rel="alternate"></link><published>2009-12-10T18:12:00+08:00</published><updated>2009-12-10T18:12:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-12-10:/2009/12/10/chroma-key-and-thresholding-in-flash-pixel-bender-revised/</id><summary type="html">&lt;p&gt;&lt;img alt="yellowFiltered" src="/files/2009/yellowFiltered.png" title="yellowFiltered"/&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a href="/files/2009/chromaKey.html"&gt;Demo&lt;/a&gt; (Click to toggle filter)&lt;/h3&gt;
&lt;p&gt;&lt;a href="/files/2009/chromaKey.zip"&gt;source (Flex project including pbk)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have been very busy since the last few weeks… so the chroma key
filter was put aside for a long time until today :)&lt;/p&gt;
&lt;p&gt;I have used conditional compile in the filter to avoid having if-else in
the runtime, hopefully …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="yellowFiltered" src="/files/2009/yellowFiltered.png" title="yellowFiltered"/&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a href="/files/2009/chromaKey.html"&gt;Demo&lt;/a&gt; (Click to toggle filter)&lt;/h3&gt;
&lt;p&gt;&lt;a href="/files/2009/chromaKey.zip"&gt;source (Flex project including pbk)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have been very busy since the last few weeks… so the chroma key
filter was put aside for a long time until today :)&lt;/p&gt;
&lt;p&gt;I have used conditional compile in the filter to avoid having if-else in
the runtime, hopefully can increase performance… Anyone volunteer to
measure it and post the different?&lt;/p&gt;</content><category term="experiment"></category><category term="Flash"></category><category term="Pixel Bender"></category></entry><entry><title>Pixel Bender port of Scale2x and Scale3x</title><link href="https://blog.onthewings.net/2009/09/28/pixel-bender-port-of-scale2x-and-scale3x/" rel="alternate"></link><published>2009-09-28T03:35:00+08:00</published><updated>2009-09-28T03:35:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-09-28:/2009/09/28/pixel-bender-port-of-scale2x-and-scale3x/</id><summary type="html">&lt;p&gt;&lt;img alt="scale2x" src="/files/2009/scale2x.png" title="scale2x"/&gt;&lt;/p&gt;
&lt;p&gt;When I first saw the &lt;a href="http://en.nicoptere.net/?p=6"&gt;Scale2x, scale3x &lt;span class="caps"&gt;AS3&lt;/span&gt;&lt;/a&gt; I am impressed. The
algorithm is from &lt;a href="http://scale2x.sourceforge.net/algorithm.html"&gt;scale2x sourceforge project&lt;/a&gt; and the &lt;span class="caps"&gt;AS3&lt;/span&gt; port is
coded as a class that is very easy to reuse. Surely the &lt;span class="caps"&gt;AS3&lt;/span&gt; port author
nicoptere can make a &lt;span class="caps"&gt;PB&lt;/span&gt; port too as you may find out …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;img alt="scale2x" src="/files/2009/scale2x.png" title="scale2x"/&gt;&lt;/p&gt;
&lt;p&gt;When I first saw the &lt;a href="http://en.nicoptere.net/?p=6"&gt;Scale2x, scale3x &lt;span class="caps"&gt;AS3&lt;/span&gt;&lt;/a&gt; I am impressed. The
algorithm is from &lt;a href="http://scale2x.sourceforge.net/algorithm.html"&gt;scale2x sourceforge project&lt;/a&gt; and the &lt;span class="caps"&gt;AS3&lt;/span&gt; port is
coded as a class that is very easy to reuse. Surely the &lt;span class="caps"&gt;AS3&lt;/span&gt; port author
nicoptere can make a &lt;span class="caps"&gt;PB&lt;/span&gt; port too as you may find out many &lt;span class="caps"&gt;PB&lt;/span&gt; cool stuff
over &lt;a href="http://en.nicoptere.net/"&gt;his blog&lt;/a&gt;, but my pixel bending desire force me to do it myself :P&lt;/p&gt;
&lt;p&gt;Here below the video shows my demo. I get a camera capture stream and
used &lt;a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;amp;extid=1760025"&gt;Posterizer which is downloaded from Pixel Bender Exchange&lt;/a&gt; to
convert the image to 4-color-only, and than use the scale2x filter to
enlarge the low resolution capture. The top-left corner thumbnail-like
image is actually the original 1:1 input(160*120).&lt;/p&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="390" src="//www.youtube.com/embed/3PHPc2it4ww" width="640"&gt;&lt;/iframe&gt;
&lt;p&gt;It is quite interesting to see for scale2x, &lt;span class="caps"&gt;PB&lt;/span&gt;’s version nearly doubles
the performance of &lt;span class="caps"&gt;AS3&lt;/span&gt;’s. But for scale3x, there is not much different
between &lt;span class="caps"&gt;PB&lt;/span&gt; and &lt;span class="caps"&gt;AS3&lt;/span&gt;. I think it is because scale3x has too many if-else
which &lt;span class="caps"&gt;PB&lt;/span&gt; is not strong at.&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;BTW&lt;/span&gt;, I discovered a bug in &lt;span class="caps"&gt;PB&lt;/span&gt; while coding this. The bug make my code
much longer as I work-a-round it… I reported it to the &lt;a href="http://forums.adobe.com/thread/497374"&gt;&lt;span class="caps"&gt;PB&lt;/span&gt; forum&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="/files/2009/pbScaleX.html"&gt;Demo app&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="/files/2009/pbScaleX.zip"&gt;Demo app’s Flex project with Pixel Bender source&lt;/a&gt; (The shorter but
buggy versions are included too.)&lt;/p&gt;</content><category term="Flash"></category><category term="Pixel Bender"></category></entry><entry><title>Bicubic resampling by Pixel Bender</title><link href="https://blog.onthewings.net/2009/08/25/bicubic-resampling-by-pixel-bender/" rel="alternate"></link><published>2009-08-25T07:51:00+08:00</published><updated>2009-08-25T07:51:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-08-25:/2009/08/25/bicubic-resampling-by-pixel-bender/</id><summary type="html">&lt;p&gt;There is &lt;a href="http://www.brooksandrus.com/blog/2009/03/11/bilinear-resampling-with-flash-player-and-pixel-bender/"&gt;bilinear resampling by Pixel Bender&lt;/a&gt; already, why not
bicubic too?&lt;/p&gt;
&lt;p&gt;With the very helpful &lt;a href="http://www.paulinternet.nl/?page=bicubic"&gt;Java implementation&lt;/a&gt;, I can get bicubic
resampling running in Pixel Bender in hours.&lt;/p&gt;
&lt;p&gt;Here is my result, along with the resampling results in PhotoShop as a comparison:&lt;/p&gt;
&lt;p&gt;Source image (4x4), scaled by your browser …&lt;/p&gt;</summary><content type="html">&lt;p&gt;There is &lt;a href="http://www.brooksandrus.com/blog/2009/03/11/bilinear-resampling-with-flash-player-and-pixel-bender/"&gt;bilinear resampling by Pixel Bender&lt;/a&gt; already, why not
bicubic too?&lt;/p&gt;
&lt;p&gt;With the very helpful &lt;a href="http://www.paulinternet.nl/?page=bicubic"&gt;Java implementation&lt;/a&gt;, I can get bicubic
resampling running in Pixel Bender in hours.&lt;/p&gt;
&lt;p&gt;Here is my result, along with the resampling results in PhotoShop as a comparison:&lt;/p&gt;
&lt;p&gt;Source image (4x4), scaled by your browser):&lt;/p&gt;
&lt;p&gt;&lt;img alt="Source image (4x4), scaled by your browser)" class="size-full wp-image-506 " height="200" scale="0" src="/files/2009/16color.png" title="16color image" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;Source image enlarged in &lt;span class="caps"&gt;PS&lt;/span&gt; (nearest neighbor):&lt;/p&gt;
&lt;p&gt;&lt;img alt="Source image enlarged in PS (nearest neighbor)" class="size-full wp-image-507 " height="200" scale="0" src="/files/2009/16color_psNearest.png" title="16color_psNearest" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;Bicubic resampling by Pixel Bender:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bicubic resampling by Pixel Bender" class="size-full wp-image-508 " height="200" scale="0" src="/files/2009/16color_pbBicubic.png" title="16color_pbBicubic" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;There is some difference with PhotoShop’s versions (below), hope it’s
not my mistake…&lt;/p&gt;
&lt;p&gt;Bicubic resampling by PhotoShop:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bicubic resampling by PhotoShop." class="size-full wp-image-509 " height="200" scale="0" src="/files/2009/16color_psBicubic.png" title="16color_psBicubic" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;Bicubic smoother by PhotoShop:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bicubic smoother in PhotoShop" class="size-full wp-image-510 " height="200" scale="0" src="/files/2009/16color_psBicubicSmoother.png" title="16color_psBicubicSmoother" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;Bicubic sharper by PhotoShop:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Bicubic sharper in PhotoShop" class="size-full wp-image-511 " height="200" scale="0" src="/files/2009/16color_psBicubicShaper.png" title="16color_psBicubicShaper" width="200"/&gt;&lt;/p&gt;
&lt;p&gt;My codes can be downloaded below:&lt;br/&gt;
&lt;a href="/files/2009/bicubicResampling.zip"&gt;Bicubic resampling sample program source (with &lt;span class="caps"&gt;PB&lt;/span&gt; source)&lt;/a&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Update:&lt;br/&gt;
Notified by author of the Java version, the Java code was wrong and has
been updated. Here below is my updated code:&lt;br/&gt;
&lt;a href="/files/2010/bicubicResampling.zip"&gt;Bicubic resampling sample program source (with &lt;span class="caps"&gt;PB&lt;/span&gt; source)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;updated output of &lt;span class="caps"&gt;PB&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt="updated output of PB" src="/files/2009/pbBicubic.png"/&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Update (2010-11-17):&lt;br/&gt;
Once again notified by Paul, the author of the Java version, there is
something need to be updated. Here below is my updated code:&lt;br/&gt;
&lt;a href="/files/2009/bicubicResampling1.zip"&gt;Bicubic resampling sample program source (with &lt;span class="caps"&gt;PB&lt;/span&gt; source)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;updated output of &lt;span class="caps"&gt;PB&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img alt="updated output of PB" src="/files/2009/pbBicubic1.png"/&gt;&lt;/p&gt;</content><category term="Flash"></category><category term="Flex"></category><category term="Pixel Bender"></category></entry><entry><title>Playing with chroma key and thresholding in Flash (with Pixel Bender)</title><link href="https://blog.onthewings.net/2009/08/18/playing-with-chroma-key-and-thresholding-in-flash-with-pixel-bender/" rel="alternate"></link><published>2009-08-18T06:22:00+08:00</published><updated>2009-08-18T06:22:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-08-18:/2009/08/18/playing-with-chroma-key-and-thresholding-in-flash-with-pixel-bender/</id><summary type="html">&lt;p&gt;While &lt;a href="http://www.flickr.com/photos/andy-li/sets/72157621818199411/"&gt;traveling with my gf in Europe&lt;/a&gt;, I’m planning to develop a
better technique to use color marker in FLARtoolkit (which I’ve &lt;a href="https://blog.onthewings.net/2009/05/23/flartoolkit-trick-use-a-colored-marker/"&gt;tried
before&lt;/a&gt;).&lt;/p&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="390" src="//www.youtube.com/embed/coDZ7VUogh4" width="640"&gt;&lt;/iframe&gt;
&lt;p&gt;For the first step of doing so is to find a algorithm of matching
colors. Using blend mode “difference” on the image is not …&lt;/p&gt;</summary><content type="html">&lt;p&gt;While &lt;a href="http://www.flickr.com/photos/andy-li/sets/72157621818199411/"&gt;traveling with my gf in Europe&lt;/a&gt;, I’m planning to develop a
better technique to use color marker in FLARtoolkit (which I’ve &lt;a href="https://blog.onthewings.net/2009/05/23/flartoolkit-trick-use-a-colored-marker/"&gt;tried
before&lt;/a&gt;).&lt;/p&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="390" src="//www.youtube.com/embed/coDZ7VUogh4" width="640"&gt;&lt;/iframe&gt;
&lt;p&gt;For the first step of doing so is to find a algorithm of matching
colors. Using blend mode “difference” on the image is not flexible and
may not fit all situations. I decided to calculate the difference by
comparing hue, saturation and brightness of the colors and then
threshold the image.&lt;/p&gt;
&lt;p&gt;This is very similar to (if not exactly) doing &lt;a href="http://en.wikipedia.org/wiki/Chroma_key"&gt;chroma key&lt;/a&gt;. Maybe
there is some awesome beautiful chroma key algorithm but I can’t find a
fast and flexible enough to do so. If you know one, please tell me. :)&lt;/p&gt;
&lt;p&gt;One problem I faced is choosing between color space models. &lt;span class="caps"&gt;RGB&lt;/span&gt; surely
wouldn’t be the choice since it do not give hue value directly. There
are &lt;span class="caps"&gt;HSV&lt;/span&gt; and &lt;span class="caps"&gt;HSL&lt;/span&gt; I found to be quite suitable. The two models share the
same algorithm to calculate hue but have different ones for saturation
and brightness. After reading the &lt;a href="http://en.wikipedia.org/wiki/HSL_and_HSV"&gt;algorithms&lt;/a&gt;, my decision is… try
both. :P&lt;/p&gt;
&lt;p&gt;Another problem is how to preform thresholding. First method is after
calculating the pixel difference, add the difference in hue, saturation
and brightness altogether with weightings and do a one-time threshold to
the grayscale image. Second method is calculate the difference and give
threshold limits to the three channels (H,S,V or H,S,L), only the pixels
pass all the three thresholds will be white. First method should be more
easily to incorporate with other filters developed for &lt;span class="caps"&gt;AR&lt;/span&gt; (like the very
hot &lt;a href="http://blog.inspirit.ru/?p=322"&gt;adaptive thresholding&lt;/a&gt;), but the second method can be more
precise.  Finally I tried both too…&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;strong&gt;&lt;a href="/files/2009/colorDifference.html"&gt;Here is the result&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;. While
I have set some default values to the filters, be sure to play around
with the values when you change the target color. There wouldn’t be a
set of values that fits all methods and situations. :)&lt;/p&gt;
&lt;p&gt;I’ll try integrate it with FLARtoolkit and release the source when it is
ready, be sure to check back soon. :)&lt;/p&gt;
&lt;p&gt;Update:&lt;br/&gt;
&lt;a href="https://blog.onthewings.net/2009/12/10/chroma-key-and-thresholding-in-flash-pixel-bender-revised/"&gt;Source and new demo is here!&lt;/a&gt;&lt;/p&gt;</content><category term="experiment"></category><category term="Flash"></category><category term="Flex"></category><category term="Pixel Bender"></category></entry><entry><title>FLARtoolkit trick: use a colored marker</title><link href="https://blog.onthewings.net/2009/05/23/flartoolkit-trick-use-a-colored-marker/" rel="alternate"></link><published>2009-05-23T10:40:00+08:00</published><updated>2009-05-23T10:40:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-05-23:/2009/05/23/flartoolkit-trick-use-a-colored-marker/</id><summary type="html">&lt;iframe allowfullscreen="" frameborder="0" height="390" src="//www.youtube.com/embed/DY7TPBRPpFI" width="640"&gt;&lt;/iframe&gt;
&lt;h2&gt;Reasons why should we use colored marker instead of standard black and white only marker&lt;/h2&gt;
&lt;h3&gt;Using a black and white only marker is boring&lt;/h3&gt;
&lt;p&gt;There are more and more &lt;span class="caps"&gt;AR&lt;/span&gt; applications in the world, but seems
everybody use only the black square marker. May be the public is not yet …&lt;/p&gt;</summary><content type="html">&lt;iframe allowfullscreen="" frameborder="0" height="390" src="//www.youtube.com/embed/DY7TPBRPpFI" width="640"&gt;&lt;/iframe&gt;
&lt;h2&gt;Reasons why should we use colored marker instead of standard black and white only marker&lt;/h2&gt;
&lt;h3&gt;Using a black and white only marker is boring&lt;/h3&gt;
&lt;p&gt;There are more and more &lt;span class="caps"&gt;AR&lt;/span&gt; applications in the world, but seems
everybody use only the black square marker. May be the public is not yet
bored by the black square yet, but if can use other color for the
square, we can integrate the marker into real-life objects more
beautifully and more flexible.&lt;/p&gt;
&lt;h3&gt;Increase marker detection performance&lt;/h3&gt;
&lt;p&gt;The internal algorithm of &lt;span class="caps"&gt;AR&lt;/span&gt; marker detection has a characteristic that,
the less pixels’ color is the same of the marker, faster the detection
can be done. When we use black square marker, the detector will waste a
lot of time to process non-marker pixels as you can imagine that it is
common to have black objects in real-life (especially we the Chinese
people have black hair). So if we target less common color, the detector
will be able to ignore most of the non-marker area.&lt;/p&gt;
&lt;h2&gt;How to achieve this in FLARtoolkit&lt;/h2&gt;
&lt;p&gt;We will create a custom detector class since we need to work at lower
level of the FLARtoolkit. If you have not look into the internal classes
of FLARtoolkit (because the &lt;a href="http://words.transmote.com/wp/20090328/flarmanager-v03/"&gt;FLARmanager&lt;/a&gt; is so much easier to work
with ;-) ), there are two detectors: FLARSingleMarkerDetector and
FLARMultiMarkerDetector. As their names suggest, one is for single
marker detection and the other one can detect multiple markers. For
simplicity, I will go through only the single detection for a red marker
(if you want me to cover the other ones too, leave comment).&lt;/p&gt;
&lt;p&gt;First we just copy all the codes inside FLARSingleMarkerDetector to a
new class, I named it FLARSingleRedMarkerDetector.&lt;/p&gt;
&lt;p&gt;To detect markers, we use the detectMarkerLite method, which is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;public function detectMarkerLite(i_raster:IFLARRgbRaster, i_threshold:int):Boolean
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;IFLARRgbRaster wraps a BitmapData, we can get it by:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;var&lt;/span&gt; &lt;span class="nt"&gt;srcImg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;BitmapData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;i_raster&lt;/span&gt; &lt;span class="nt"&gt;as&lt;/span&gt; &lt;span class="nt"&gt;FLARRgbRaster_BitmapData&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;bitmapData&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Originally, the method uses a threshold filter to extract black areas
and give the result to other classes to process. As you might think of,
we can simply swap the filter code. Originally the black areas will be
turned to white pixels and others will be turned black and be ignored.
We now want to detect red markers, so just try to turn everything black
except the red regions to white. You may use ColorTransform if you want,
but I am now obsessed with PixelBender. My version of kernel is:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;kernel&lt;/span&gt; &lt;span class="nt"&gt;extractRedARMarker&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;   &lt;span class="nt"&gt;namespace&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"net.onthewings.filters"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;vendor&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Andy Li"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;version&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;description&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"used for FLARtoolkit, pre-proccess for red marker."&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;input&lt;/span&gt; &lt;span class="err"&gt;image4&lt;/span&gt; &lt;span class="err"&gt;src&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="err"&gt;output&lt;/span&gt; &lt;span class="err"&gt;pixel4&lt;/span&gt; &lt;span class="err"&gt;dst&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="err"&gt;parameter&lt;/span&gt; &lt;span class="err"&gt;float&lt;/span&gt; &lt;span class="err"&gt;threshold&amp;lt;&lt;/span&gt;
        &lt;span class="n"&gt;minValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;defaultValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"decrease to increase likelihood of marker detection."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="err"&gt;void&lt;/span&gt;
    &lt;span class="err"&gt;evaluatePixel()&lt;/span&gt;
    &lt;span class="err"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;float4&lt;/span&gt; &lt;span class="err"&gt;p&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="err"&gt;sampleNearest(src,outCoord())&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="err"&gt;float&lt;/span&gt; &lt;span class="err"&gt;sum&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="err"&gt;p.r+p.g+p.b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="err"&gt;float&lt;/span&gt; &lt;span class="err"&gt;val&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="err"&gt;p.r&lt;/span&gt; &lt;span class="err"&gt;-&lt;/span&gt; &lt;span class="err"&gt;(p.g&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;p.b)*0.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="err"&gt;if&lt;/span&gt; &lt;span class="err"&gt;(val+(1.0-(sum/3.0))*0.1&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="err"&gt;threshold)&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
            &lt;span class="err"&gt;val&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="err"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="err"&gt;val&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="err"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nt"&gt;dst&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nt"&gt;float4&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;val&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;val&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;val&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nt"&gt;1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that I let the dark red pass the threshold easier since I find it
is common the web cam image is too dark.&lt;/p&gt;
&lt;p&gt;To use the finished detector class:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nx"&gt;tempFLARRgbRaster_BitmapData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bitmapData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;videoDisplay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;detectMarkerLite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tempFLARRgbRaster_BitmapData&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;170&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
    &lt;span class="nx"&gt;detector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getTransformMatrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastDetectionResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;//FLARPVGeomUtils is from FLARmanager&lt;/span&gt;
    &lt;span class="nx"&gt;overlay3dObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transform&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;FLARPVGeomUtils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;convertFLARMatrixToPVMatrix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;lastDetectionResult&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;overlay3dObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;overlay3dObj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;visible&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now you get all the concepts. So let’s skip all the boring stuff and
&lt;a href="http://www.onthewings.net/"&gt;see it in action&lt;/a&gt;. Or &lt;a href="/files/2009/redmarkerdetection.zip"&gt;get the finished codes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Happy &lt;span class="caps"&gt;AR&lt;/span&gt;!&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Update: Here I have a &lt;span class="caps"&gt;PB&lt;/span&gt; kernel that works with any color. &lt;a href="https://blog.onthewings.net/2009/12/10/chroma-key-and-thresholding-in-flash-pixel-bender-revised/"&gt;Try it&lt;/a&gt;!&lt;/p&gt;</content><category term="FLARtoolkit"></category><category term="Flash"></category><category term="Pixel Bender"></category><category term="trick"></category></entry><entry><title>The Bilateral Blur Filter for Flash is now on Pixel Bender Exchange (in staff picks!)</title><link href="https://blog.onthewings.net/2009/04/24/the-bilateral-blur-filter-for-flash-is-now-on-pixel-bender-exchange-in-staff-picks/" rel="alternate"></link><published>2009-04-24T00:19:00+08:00</published><updated>2009-04-24T00:19:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-04-24:/2009/04/24/the-bilateral-blur-filter-for-flash-is-now-on-pixel-bender-exchange-in-staff-picks/</id><summary type="html">&lt;p&gt;I’ve put my bilateral blur filter on Pixel Bender Exchange and it is
selected as staff picks!&lt;/p&gt;
&lt;p&gt;Go and download it from the page: &lt;a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;amp;loc=en_us&amp;amp;extid=1789025"&gt;Bilateral Blur Filter for Flash on
Pixel Bender Exchange&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;P.S.. That one is optimized, processing time originally is 2 - 3s , it’s
now 0 …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I’ve put my bilateral blur filter on Pixel Bender Exchange and it is
selected as staff picks!&lt;/p&gt;
&lt;p&gt;Go and download it from the page: &lt;a href="http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&amp;amp;loc=en_us&amp;amp;extid=1789025"&gt;Bilateral Blur Filter for Flash on
Pixel Bender Exchange&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;P.S.. That one is optimized, processing time originally is 2 - 3s , it’s
now 0.6 - 0.7s (for a 320*240 image).&lt;/p&gt;</content><category term="Flash"></category><category term="Pixel Bender"></category></entry><entry><title>Bilateral Blur by Pixel Bender</title><link href="https://blog.onthewings.net/2009/04/14/bilateral-blur-by-pixel-bender/" rel="alternate"></link><published>2009-04-14T22:24:00+08:00</published><updated>2009-04-14T22:24:00+08:00</updated><author><name>Andy Li</name></author><id>tag:blog.onthewings.net,2009-04-14:/2009/04/14/bilateral-blur-by-pixel-bender/</id><summary type="html">&lt;p&gt;I’ve been working on implementing a bilateral blur for Flash. Currently
the functionality is ok but the performance is quite poor (on my Intel
MacBook, processing a 320x240 image takes ~2s). I’ve even tried to
replace the Gaussian weighting functions with linear functions but it
does not help …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I’ve been working on implementing a bilateral blur for Flash. Currently
the functionality is ok but the performance is quite poor (on my Intel
MacBook, processing a 320x240 image takes ~2s). I’ve even tried to
replace the Gaussian weighting functions with linear functions but it
does not help a lot but leads to worse quality. The problem should be
the sampling size of each pixel which I hard coded to be 9x9 square.
Reducing the sampling area would help but again reducing quality.&lt;/p&gt;
&lt;p&gt;It is frustrating that Pixel Bender in Flash do not have loops. Even
accessing vector/matrix elements with variable index is not possible.&lt;/p&gt;
&lt;p&gt;Anyway, here below is a demo.&lt;/p&gt;
&lt;p&gt;Before applying filter:
&lt;img alt="Before applying filter." src="/files/2009/before.png" title="before"/&gt;&lt;/p&gt;
&lt;p&gt;After applying filter:
&lt;img alt="After applying filter." src="/files/2009/after.png" title="after"/&gt;&lt;/p&gt;
&lt;p&gt;Hope I can further optimize it later. (or better Adobe gives us &lt;span class="caps"&gt;GPU&lt;/span&gt; mode
:lol: )&lt;/p&gt;
&lt;p&gt;&lt;span class="caps"&gt;UPDATED&lt;/span&gt;: &lt;a href="https://blog.onthewings.net/2009/04/24/the-bilateral-blur-filter-for-flash-is-now-on-pixel-bender-exchange-in-staff-picks/"&gt;See this blog post&lt;/a&gt;&lt;/p&gt;</content><category term="Flash"></category><category term="Pixel Bender"></category></entry></feed>