<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Extract shape outline points from BitmapData</title>
	<atom:link href="http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/</link>
	<description>I Flash und I Flex Jaaaa</description>
	<pubDate>Sat, 31 Jul 2010 00:24:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Box2D Flex Complex Shapes Mapping</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1594</link>
		<dc:creator>Box2D Flex Complex Shapes Mapping</dc:creator>
		<pubDate>Thu, 15 Jul 2010 18:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1594</guid>
		<description>[...] sakri.net for he&#8217;s shape outline algorithm [...]</description>
		<content:encoded><![CDATA[<p>[...] sakri.net for he&#8217;s shape outline algorithm [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blog.VETTIGHEID.com &#187; Blog Archive &#187; Grid voor TileEditor</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1327</link>
		<dc:creator>blog.VETTIGHEID.com &#187; Blog Archive &#187; Grid voor TileEditor</dc:creator>
		<pubDate>Wed, 20 Jan 2010 16:18:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1327</guid>
		<description>[...] worden deze tiles omgezet naar 1 bitmap. - Van deze bitmap wordt de rand bepaalt met behulp van deze class van Sakri Rosenstrom. - Omdat de class van iedere pixel een punt maak rond ik de punten af naar de [...]</description>
		<content:encoded><![CDATA[<p>[...] worden deze tiles omgezet naar 1 bitmap. - Van deze bitmap wordt de rand bepaalt met behulp van deze class van Sakri Rosenstrom. - Omdat de class van iedere pixel een punt maak rond ik de punten af naar de [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Og2t</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1254</link>
		<dc:creator>Og2t</dc:creator>
		<pubDate>Thu, 17 Sep 2009 15:18:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1254</guid>
		<description>You could also use GlowFilter and then threshold method (for speed) but of course it wouldn't give you pixel coords, just the transparent outline BitmapData :)</description>
		<content:encoded><![CDATA[<p>You could also use GlowFilter and then threshold method (for speed) but of course it wouldn&#8217;t give you pixel coords, just the transparent outline BitmapData <img src='http://www.sakri.net/blog/wp-includes/images/smilies/smile_sakri_blue.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: delfeld</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1249</link>
		<dc:creator>delfeld</dc:creator>
		<pubDate>Tue, 01 Sep 2009 17:08:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1249</guid>
		<description>I noticed in FlexSimpleTraceBox you are looking to find class names dynamically.  Here are some suggestions:

import flash.utils.getQualifiedClassName;

getQualifiedClassName() returns the name of a class as a String.

Creating a class dynamically:

// SomeClass could be an Object class, too, so can be pretty generic
import some.class.definition.SomeClass;
import flash.utils.getDefinitionByName;

var className:String = "SomeClassName";
classRef = getDefinitionByName(className) as Class;
imgMC = (new classRef() as SomeClass);</description>
		<content:encoded><![CDATA[<p>I noticed in FlexSimpleTraceBox you are looking to find class names dynamically.  Here are some suggestions:</p>
<p>import flash.utils.getQualifiedClassName;</p>
<p>getQualifiedClassName() returns the name of a class as a String.</p>
<p>Creating a class dynamically:</p>
<p>// SomeClass could be an Object class, too, so can be pretty generic<br />
import some.class.definition.SomeClass;<br />
import flash.utils.getDefinitionByName;</p>
<p>var className:String = &#8220;SomeClassName&#8221;;<br />
classRef = getDefinitionByName(className) as Class;<br />
imgMC = (new classRef() as SomeClass);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakri</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1227</link>
		<dc:creator>sakri</dc:creator>
		<pubDate>Thu, 02 Jul 2009 05:06:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1227</guid>
		<description>Hi Morgan,

Thanks for posting!

Did you see this post http://www.sakri.net/blog/2009/05/28/detecting-edge-pixels-with-marching-squares-algorithm/

I've also got the four pixel version running there, however, it's not bullet proof, there are a few conditions in which a "straight forward" 4 pixel version fails.</description>
		<content:encoded><![CDATA[<p>Hi Morgan,</p>
<p>Thanks for posting!</p>
<p>Did you see this post <a href="http://www.sakri.net/blog/2009/05/28/detecting-edge-pixels-with-marching-squares-algorithm/" rel="nofollow">http://www.sakri.net/blog/2009/05/28/detecting-edge-pixels-with-marching-squares-algorithm/</a></p>
<p>I&#8217;ve also got the four pixel version running there, however, it&#8217;s not bullet proof, there are a few conditions in which a &#8220;straight forward&#8221; 4 pixel version fails.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan Moonjob</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1226</link>
		<dc:creator>Morgan Moonjob</dc:creator>
		<pubDate>Wed, 01 Jul 2009 23:39:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1226</guid>
		<description>I took a minute to adapt your code to the 4-pixel marching squares algorithm... :D

package com.MorganMoonjob.edgeDetection{
	import __AS3__.vec.Vector;
	import flash.display.BitmapData;
	import flash.geom.Point;
	
	public class EdgeScanner{
		protected var _scanPts:Vector.=Vector.([
																new Point(0,0),
																new Point(1,0),
																new Point(0,1),
																new Point(1,1)
																	]);
		protected var _variations:Object={
								"0000":new Point(1,0),
								"0001":new Point(0,1),
								"0010":new Point(-1,0),
								"0011":new Point(-1,0),
								"0100":new Point(1,0),
								"0101":new Point(0,1),
								"0110":new Point(-1,0),
								"0111":new Point(-1,0),
								"1000":new Point(0,-1),
								"1001":new Point(0,-1),
								"1010":new Point(0,-1),
								"1011":new Point(0,-1),
								"1100":new Point(1,0),
								"1101":new Point(0,1),
								"1110":new Point(0,-1),
								"1111":new Point(1,0)
		}
		protected var _target:BitmapData;
		protected var _grid:String;
		
		public function getCurrentGrid():String{
			return _grid+"";
		}
		protected var _position:Point;
		public function get position():Point{
			return _position;
		}
		
		public function EdgeScanner(target:BitmapData){
			reset(target);
		}
		
		public function reset(target:BitmapData):void{
			_grid="";
			_target=target;
		}
		
		public function moveTo(p:Point):void{
			_position=p;
			updateScanGrid();
		}
		protected function updateScanGrid():void{
			_grid="";
			var p:Point;
			for(var i:uint=0;i0x0 ? "1" : "0");
			}
		}
		
		public function getNextEdgePoint():Point{
			var p:Point=_variations[_grid];
			if(p==null)throw new Error("BitmapEdgeScanner Error : _grid:"+_grid+" , not found in _variations");
			return new Point(_position.x+p.x,_position.y+p.y);
		}
	}
}</description>
		<content:encoded><![CDATA[<p>I took a minute to adapt your code to the 4-pixel marching squares algorithm&#8230; <img src='http://www.sakri.net/blog/wp-includes/images/smilies/biggrin_sakri_blue.gif' alt=':D' class='wp-smiley' /> </p>
<p>package com.MorganMoonjob.edgeDetection{<br />
	import __AS3__.vec.Vector;<br />
	import flash.display.BitmapData;<br />
	import flash.geom.Point;</p>
<p>	public class EdgeScanner{<br />
		protected var _scanPts:Vector.=Vector.([<br />
																new Point(0,0),<br />
																new Point(1,0),<br />
																new Point(0,1),<br />
																new Point(1,1)<br />
																	]);<br />
		protected var _variations:Object={<br />
								&#8220;0000&#8243;:new Point(1,0),<br />
								&#8220;0001&#8243;:new Point(0,1),<br />
								&#8220;0010&#8243;:new Point(-1,0),<br />
								&#8220;0011&#8243;:new Point(-1,0),<br />
								&#8220;0100&#8243;:new Point(1,0),<br />
								&#8220;0101&#8243;:new Point(0,1),<br />
								&#8220;0110&#8243;:new Point(-1,0),<br />
								&#8220;0111&#8243;:new Point(-1,0),<br />
								&#8220;1000&#8243;:new Point(0,-1),<br />
								&#8220;1001&#8243;:new Point(0,-1),<br />
								&#8220;1010&#8243;:new Point(0,-1),<br />
								&#8220;1011&#8243;:new Point(0,-1),<br />
								&#8220;1100&#8243;:new Point(1,0),<br />
								&#8220;1101&#8243;:new Point(0,1),<br />
								&#8220;1110&#8243;:new Point(0,-1),<br />
								&#8220;1111&#8243;:new Point(1,0)<br />
		}<br />
		protected var _target:BitmapData;<br />
		protected var _grid:String;</p>
<p>		public function getCurrentGrid():String{<br />
			return _grid+&#8221;";<br />
		}<br />
		protected var _position:Point;<br />
		public function get position():Point{<br />
			return _position;<br />
		}</p>
<p>		public function EdgeScanner(target:BitmapData){<br />
			reset(target);<br />
		}</p>
<p>		public function reset(target:BitmapData):void{<br />
			_grid=&#8221;";<br />
			_target=target;<br />
		}</p>
<p>		public function moveTo(p:Point):void{<br />
			_position=p;<br />
			updateScanGrid();<br />
		}<br />
		protected function updateScanGrid():void{<br />
			_grid=&#8221;";<br />
			var p:Point;<br />
			for(var i:uint=0;i0&#215;0 ? &#8220;1&#8243; : &#8220;0&#8243;);<br />
			}<br />
		}</p>
<p>		public function getNextEdgePoint():Point{<br />
			var p:Point=_variations[_grid];<br />
			if(p==null)throw new Error(&#8221;BitmapEdgeScanner Error : _grid:&#8221;+_grid+&#8221; , not found in _variations&#8221;);<br />
			return new Point(_position.x+p.x,_position.y+p.y);<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rothrock</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1157</link>
		<dc:creator>Rothrock</dc:creator>
		<pubDate>Wed, 20 May 2009 06:05:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1157</guid>
		<description>I haven't actually made an AS3 version other than modifying what you posted here. Your example is the same idea, just not having a 4-grid. So in your class where you have BitmapEdgeScanner class you replace (or make a second version) of the _scan_points and _variations properties. Also change the loop in updateScanGrid to i&#60;4.

I think your shape extractor is a lot faster than trying to use the marching square to march over all the empty space and the interiors.

And don't forget to not double size extract the shapes! That is where the biggest time saving seems to be. I was also looking at BitmapData.lock/unlock in some places, but I couldn't find anywhere where it seemed to make a really large difference.</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t actually made an AS3 version other than modifying what you posted here. Your example is the same idea, just not having a 4-grid. So in your class where you have BitmapEdgeScanner class you replace (or make a second version) of the _scan_points and _variations properties. Also change the loop in updateScanGrid to i&lt;4.</p>
<p>I think your shape extractor is a lot faster than trying to use the marching square to march over all the empty space and the interiors.</p>
<p>And don&#8217;t forget to not double size extract the shapes! That is where the biggest time saving seems to be. I was also looking at BitmapData.lock/unlock in some places, but I couldn&#8217;t find anywhere where it seemed to make a really large difference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sakri</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1156</link>
		<dc:creator>sakri</dc:creator>
		<pubDate>Wed, 20 May 2009 05:14:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1156</guid>
		<description>Hi Rothrock,

Thanks for taking the time to post :) I had a quick look at Marching Squares on wikipedia, looks great! In retrospect, I'm wondering why I went for 9 squares :D

Do you have an AS3 implementation of Marching Squares?  I'd love to give it a spin myself...

Thanks again :)


Sakri</description>
		<content:encoded><![CDATA[<p>Hi Rothrock,</p>
<p>Thanks for taking the time to post <img src='http://www.sakri.net/blog/wp-includes/images/smilies/smile_sakri_blue.gif' alt=':)' class='wp-smiley' /> I had a quick look at Marching Squares on wikipedia, looks great! In retrospect, I&#8217;m wondering why I went for 9 squares <img src='http://www.sakri.net/blog/wp-includes/images/smilies/biggrin_sakri_blue.gif' alt=':D' class='wp-smiley' /> </p>
<p>Do you have an AS3 implementation of Marching Squares?  I&#8217;d love to give it a spin myself&#8230;</p>
<p>Thanks again <img src='http://www.sakri.net/blog/wp-includes/images/smilies/smile_sakri_blue.gif' alt=':)' class='wp-smiley' /> </p>
<p>Sakri</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rothrock</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1155</link>
		<dc:creator>Rothrock</dc:creator>
		<pubDate>Tue, 19 May 2009 21:11:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1155</guid>
		<description>Yeah I think Marching Squares is a good choice. I used your algorithm (not the whole example) on a 264 x 290 bitmap with 5 shapes in it. (Just doodles with the paint brush.)

Using the double sized extraction and your 9-grid search it took 137 milliseconds.
Using the double sized extraction and a 4-grid search it took 124 milliseconds

Using the single sized extraction and a 4-grid search it took 44 milliseconds

I couldn't use the 9-grid search with the single sized extraction because my shape throws an error.

But the combination of not having to double the bitmap and having to only test 4 pixel values is a lot faster than your current implementation.

Here is the scan points:

   new Point(0,-1),
   new Point(-1,-1),
   new Point(-1,0),
   new Point(0,0)


With a 4-grid there are only 16 possible combinations compared to the 512 for a nine grid. I'm not sure how you are getting away with 40 combinations, but I'm guessing it has to do with the center always being an on pixel and the doubling must rule out some others. Maybe? With 4 grid there are two combinations that don't occur, all on and all off so the 14 variations are:

	"0001" :new Point(1,0),
	"0010" :new Point(0,1),
	"0011" :new Point(1,0),
	"0100" :new Point(-1,0),
	"0101" :new Point(1,0),
	"0110" :new Point(0,1),
	"0111" :new Point(1,0),
	"1000" :new Point(0,-1),
	"1001" :new Point(0,-1),
	"1010" :new Point(0,1),
	"1011" :new Point(0,-1),
	"1100" :new Point(-1,0),
	"1101" :new Point(-1,0),
	"1110" :new Point(0,1)

There are two ambiguous variations 0101 and 1010. Those whould be where a shape approaches itself at an angle but doesn't touch. I haven't tried it yet to see if that can cause an "infinite" loop.</description>
		<content:encoded><![CDATA[<p>Yeah I think Marching Squares is a good choice. I used your algorithm (not the whole example) on a 264 x 290 bitmap with 5 shapes in it. (Just doodles with the paint brush.)</p>
<p>Using the double sized extraction and your 9-grid search it took 137 milliseconds.<br />
Using the double sized extraction and a 4-grid search it took 124 milliseconds</p>
<p>Using the single sized extraction and a 4-grid search it took 44 milliseconds</p>
<p>I couldn&#8217;t use the 9-grid search with the single sized extraction because my shape throws an error.</p>
<p>But the combination of not having to double the bitmap and having to only test 4 pixel values is a lot faster than your current implementation.</p>
<p>Here is the scan points:</p>
<p>   new Point(0,-1),<br />
   new Point(-1,-1),<br />
   new Point(-1,0),<br />
   new Point(0,0)</p>
<p>With a 4-grid there are only 16 possible combinations compared to the 512 for a nine grid. I&#8217;m not sure how you are getting away with 40 combinations, but I&#8217;m guessing it has to do with the center always being an on pixel and the doubling must rule out some others. Maybe? With 4 grid there are two combinations that don&#8217;t occur, all on and all off so the 14 variations are:</p>
<p>	&#8220;0001&#8243; :new Point(1,0),<br />
	&#8220;0010&#8243; :new Point(0,1),<br />
	&#8220;0011&#8243; :new Point(1,0),<br />
	&#8220;0100&#8243; :new Point(-1,0),<br />
	&#8220;0101&#8243; :new Point(1,0),<br />
	&#8220;0110&#8243; :new Point(0,1),<br />
	&#8220;0111&#8243; :new Point(1,0),<br />
	&#8220;1000&#8243; :new Point(0,-1),<br />
	&#8220;1001&#8243; :new Point(0,-1),<br />
	&#8220;1010&#8243; :new Point(0,1),<br />
	&#8220;1011&#8243; :new Point(0,-1),<br />
	&#8220;1100&#8243; :new Point(-1,0),<br />
	&#8220;1101&#8243; :new Point(-1,0),<br />
	&#8220;1110&#8243; :new Point(0,1)</p>
<p>There are two ambiguous variations 0101 and 1010. Those whould be where a shape approaches itself at an angle but doesn&#8217;t touch. I haven&#8217;t tried it yet to see if that can cause an &#8220;infinite&#8221; loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rothrock</title>
		<link>http://www.sakri.net/blog/2009/04/13/extract-shape-outline-points-from-bitmapdata/#comment-1154</link>
		<dc:creator>Rothrock</dc:creator>
		<pubDate>Mon, 18 May 2009 22:54:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.sakri.net/blog/?p=274#comment-1154</guid>
		<description>Have you looked at the Marching Squares algorithm? It uses a 2x2 grid so you don't need to double the size of the bitmap. That was the first thing I was looking into using with blob detection. Of course it doesn't give you diagonals...

I also found another algorithm that I don't yet understand that is described in this paper:

http://www.iis.sinica.edu.tw/~fchang/paper/component_labeling_cviu.pdf</description>
		<content:encoded><![CDATA[<p>Have you looked at the Marching Squares algorithm? It uses a 2&#215;2 grid so you don&#8217;t need to double the size of the bitmap. That was the first thing I was looking into using with blob detection. Of course it doesn&#8217;t give you diagonals&#8230;</p>
<p>I also found another algorithm that I don&#8217;t yet understand that is described in this paper:</p>
<p><a href="http://www.iis.sinica.edu.tw/~fchang/paper/component_labeling_cviu.pdf" rel="nofollow">http://www.iis.sinica.edu.tw/~fchang/paper/component_labeling_cviu.pdf</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
