<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Carlo Alducente&#039;s Blog &#187; DIFFERENCE</title>
	<atom:link href="http://labs.alducente.com/tag/difference/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.alducente.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Nov 2009 01:04:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>AS3 Edge Detection Demo</title>
		<link>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/</link>
		<comments>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 01:04:57 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[DIFFERENCE]]></category>
		<category><![CDATA[edge detection]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=178</guid>
		<description><![CDATA[So after posting about a technique to detect edges in AS3, I decided to take a little bit of time today to actually play with it. Check out the vid: The demo used BitmapData along with the &#8220;difference&#8221; blendmode to extract the edges from the webcam feed. Using BitmapData&#8217;s hitTest method, I was able to [...]]]></description>
			<content:encoded><![CDATA[<p>So after posting about a <a href="http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/">technique to detect edges</a> in AS3, I decided to take a little bit of time today to actually play with it. Check out the vid:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/YD7soPmI_wQ&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/YD7soPmI_wQ&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object></p>
<p>The demo used BitmapData along with the &#8220;difference&#8221; blendmode to extract the edges from the webcam feed. Using BitmapData&#8217;s hitTest method, I was able to check whether my sprite is hitting an edge. This was a pretty quick and simple demo (1hr and 147 lines of code! Woot!), so that I could actually see this thing in action. &#8220;Line Rider&#8221; anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/11/11/as3-edge-detection-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BlendMode.DIFFERENCE and why it&#8217;s awesome.</title>
		<link>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/</link>
		<comments>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 15:01:48 +0000</pubDate>
		<dc:creator>alducente</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[BlendMode]]></category>
		<category><![CDATA[DIFFERENCE]]></category>
		<category><![CDATA[edge detection]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://labs.alducente.com/?p=135</guid>
		<description><![CDATA[Straight from the CS3 Help section: Compares the constituent colors of the display object with the colors of its background, and subtracts the darker of the values of the two constituent colors from the lighter value. This setting is commonly used for more vibrant colors. For example, if the display object has a pixel with [...]]]></description>
			<content:encoded><![CDATA[<p><em>Straight from the CS3 Help section:</em></p>
<blockquote><p>Compares the constituent colors of the display object with the colors of its background, and subtracts the darker of the values of the two constituent colors from the lighter value. This setting is commonly used for more vibrant colors.</p>
<p>For example, if the display object has a pixel with an RGB value of 0xFFCC33, and the background pixel has an RGB value of 0xDDF800, the resulting RGB value for the displayed pixel is 0x222C33 (because 0xFF &#8211; 0xDD = 0&#215;22, 0xF8 &#8211; 0xCC = 0x2C, and 0&#215;33 &#8211; 0&#215;00 = 0&#215;33).</p></blockquote>
<p>So as an example, let&#8217;s say I have two Sprites, sprite &#8220;A&#8221; &amp; sprite &#8220;B&#8221;:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a_b.jpg"><img class="aligncenter size-full wp-image-137" title="difference_a_b" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a_b.jpg" alt="difference_a_b" width="244" height="120" /></a></p>
<p>If I was to set sprite B&#8217;s blendMode property to BlendMode.DIFFERENCE and place it on top of sprite A, I would end up with something like this:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_result.jpg"><img class="aligncenter size-full wp-image-145" title="difference_result" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_result.jpg" alt="difference_result" width="100" height="98" /></a></p>
<p><strong>So why is this useful?</strong></p>
<p>Other than for creating cool visuals, we can use this feature to detect edges within any display object. So let&#8217;s pretend I used a second instance of sprite A in place of sprite B and went through the same steps, I would pretty much end up with a black box since there is no difference in pixels between the two sprites. But if I was to move that second instance of sprite A 1 pixel down and 1 pixel right, I would end up with something like this:</p>
<p><a href="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a.jpg"><img class="aligncenter size-full wp-image-150" title="difference_a" src="http://labs.alducente.com/wp-content/uploads/2009/10/difference_a.jpg" alt="difference_a" width="97" height="95" /></a></p>
<p>Notice how only the edges of our star symbol is visible, making everything else (close to) black. Because of the gradient background we used in our sprites, there is a difference between the pixel values in the black areas when we moved our second sprite to be slightly unaligned with the first. The difference isn&#8217;t visible, but it is there. To solve this problem we can use <strong>BitmapData</strong> to &#8220;flatten&#8221; these two sprites and using the <strong>threshold() </strong>method, we can turn any pixels that have a value close to black into any color we choose, including pure black (0&#215;000000).</p>
<p><strong>Okay&#8230;now what?</strong></p>
<p>Since blendMode is a property of DisplayObject, we can use it with any objects that inherit from it, including Video:</p>
<p>
<object width="320" height="240">
<param name="movie" value="http://labs.alducente.com/wp-content/uploads/2009/10/blendmode_difference.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="320" height="240" src="http://labs.alducente.com/wp-content/uploads/2009/10/blendmode_difference.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
<p>This example uses 2 video objects in place of the 2 sprites we used in the earlier examples, we could probably increase performance by taking &#8220;snapshots&#8221; of the video and doing the same steps using 2 bitmaps instead of 2 Video instances, but I decided to keep it simple.</p>
<p>Using this info, we can then interact with edges extracted from the webcam to do some real-time edge detection, a cool webcam game perhaps? <a href="http://www.gskinner.com/blog/archives/2005/08/flash_8_webcam.html" onclick="urchinTracker('/outgoing/www.gskinner.com/blog/archives/2005/08/flash_8_webcam.html?referer=');">Or catching some snowflakes</a>*? but I&#8217;ll save that for another post.</p>
<p>Over &amp; out.</p>
<p>*Grant&#8217;s example was created in Flash 8(as2), which might have used a method similar to what I mentioned here, but I&#8217;m not completely sure.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.alducente.com/2009/10/16/blendmode-difference-and-why-its-awesome/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
