<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Connected component labeling - Part 3</title>
	<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/</link>
	<description>Steve Eddins manages the Image &#38; Geospatial development team at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62; and coauthored &#60;a href="http://www.mathworks.com/support/books/book5291.html?category=-1&#38;language=-1"&#62;Digital Image Processing Using MATLAB&#60;/a&#62;. He writes here about image processing concepts, algorithm implementations, and MATLAB.&#60;br&#62;&#60;br&#62;&#60;img&#62;</description>
	<pubDate>Sun, 22 Nov 2009 23:40:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-22362</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Mon, 16 Nov 2009 19:22:37 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-22362</guid>
		<description>David&#8212;I'm glad you found it useful!</description>
		<content:encoded><![CDATA[<p>David&mdash;I&#8217;m glad you found it useful!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Lalejini</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-22360</link>
		<dc:creator>David Lalejini</dc:creator>
		<pubDate>Mon, 16 Nov 2009 18:24:27 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-22360</guid>
		<description>I found your example very useful for finding connected nodes in a large set of input pairs.  I start with an Nx6 array of pixel matches between video frames, and needed to find all points in every frame that are actually of the same location on the ground.  I use Delauney tessellation to come up with unique identifiers for every node, then build the sparse adjacency matrix and apply dmperm.  Thanks for you example, it was a big help!

&lt;pre&gt;
%"matchedPixelUV" is an Nx6 array of matching pixel pairs between video
%frames, in this order: frame# pixel_u pixel_v frame# pixel_u pixel_v.

%Set up an array of unique points from all points in matchedPixelUV.
points = [matchedPixelUV(:,1:3);matchedPixelUV(:,4:6)];
points = unique(points,'rows');

%Use Delaunay Tessellation to get the indices to the unique point list from
%the original matchedPixelUV.  The k1 and k2 vectors are the matching node
%pairs, which will be used to build the adjacency matrix.
T = delaunayn(points);
[k1 d1] = dsearchn(points,T,matchedPixelUV(:,1:3));
[k2 d2] = dsearchn(points,T,matchedPixelUV(:,4:6));
display(['distance checks should be zero: d1=' num2str(sum(d1)) ', d2=' num2str(sum(d1))])
clear T d1 d2 matchedPixelUV

%Now build a sparse adjacency matrix.  Make sure it is square by
%temporarily putting ones in the upper left and lower right of the
%diagonal, then remove them.
A = sparse([1; k1; size(points,1)],[1; k2; size(points,1)],1);
clear k1 k2
A(1,1) = 0;
A(size(points,1),size(points,1))=0;

%Get the transpose of the matrix and add it back to it.  This is because
%[k1 k2] is the "forward" connection between nodes, i.e. [1 2; 1 3; 2 3; 3 4].
%However, it does not have the "return" paths [2 1; 3 1; 3 2; 4 3].
A = A+A';
% spy(A)

%Add the identity matrix so we have ones along the diagonal.
I = speye(size(A));
A = A+I;
clear I

%Use dmperm (Dulmage-Mendelsohn decomposition) to compute the connected
%components, see http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/
%for example.
[p,q,r] = dmperm(A);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I found your example very useful for finding connected nodes in a large set of input pairs.  I start with an Nx6 array of pixel matches between video frames, and needed to find all points in every frame that are actually of the same location on the ground.  I use Delauney tessellation to come up with unique identifiers for every node, then build the sparse adjacency matrix and apply dmperm.  Thanks for you example, it was a big help!</p>
<pre>
%"matchedPixelUV" is an Nx6 array of matching pixel pairs between video
%frames, in this order: frame# pixel_u pixel_v frame# pixel_u pixel_v.

%Set up an array of unique points from all points in matchedPixelUV.
points = [matchedPixelUV(:,1:3);matchedPixelUV(:,4:6)];
points = unique(points,'rows');

%Use Delaunay Tessellation to get the indices to the unique point list from
%the original matchedPixelUV.  The k1 and k2 vectors are the matching node
%pairs, which will be used to build the adjacency matrix.
T = delaunayn(points);
[k1 d1] = dsearchn(points,T,matchedPixelUV(:,1:3));
[k2 d2] = dsearchn(points,T,matchedPixelUV(:,4:6));
display(['distance checks should be zero: d1=' num2str(sum(d1)) ', d2=' num2str(sum(d1))])
clear T d1 d2 matchedPixelUV

%Now build a sparse adjacency matrix.  Make sure it is square by
%temporarily putting ones in the upper left and lower right of the
%diagonal, then remove them.
A = sparse([1; k1; size(points,1)],[1; k2; size(points,1)],1);
clear k1 k2
A(1,1) = 0;
A(size(points,1),size(points,1))=0;

%Get the transpose of the matrix and add it back to it.  This is because
%[k1 k2] is the "forward" connection between nodes, i.e. [1 2; 1 3; 2 3; 3 4].
%However, it does not have the "return" paths [2 1; 3 1; 3 2; 4 3].
A = A+A';
% spy(A)

%Add the identity matrix so we have ones along the diagonal.
I = speye(size(A));
A = A+I;
clear I

%Use dmperm (Dulmage-Mendelsohn decomposition) to compute the connected
%components, see <a href="http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/" rel="nofollow">http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/</a>
%for example.
[p,q,r] = dmperm(A);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-21515</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 26 Feb 2009 21:54:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-21515</guid>
		<description>Angel&#8212;We provide connected component code in the form of the Image Processing Toolbox.  :-)  If you have that, there's no need to implement anything yourself.  If you can't use the Image Processing Toolbox, then there's a wealth of information readily accessible on the web about connected-component labeling and breadth-first searching algorithms.</description>
		<content:encoded><![CDATA[<p>Angel&mdash;We provide connected component code in the form of the Image Processing Toolbox.  :-)  If you have that, there&#8217;s no need to implement anything yourself.  If you can&#8217;t use the Image Processing Toolbox, then there&#8217;s a wealth of information readily accessible on the web about connected-component labeling and breadth-first searching algorithms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: angel</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-21514</link>
		<dc:creator>angel</dc:creator>
		<pubDate>Thu, 26 Feb 2009 19:10:05 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-21514</guid>
		<description>am doing project on handwritten character segmentation....can i know the BFS(Breadth First Search) code for finding out the connected components?</description>
		<content:encoded><![CDATA[<p>am doing project on handwritten character segmentation&#8230;.can i know the BFS(Breadth First Search) code for finding out the connected components?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20616</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Thu, 17 Apr 2008 00:36:33 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20616</guid>
		<description>Tim&#8212;I knew that.  ;-)</description>
		<content:encoded><![CDATA[<p>Tim&mdash;I knew that.  ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20615</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Thu, 17 Apr 2008 00:34:31 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20615</guid>
		<description>OK.  I was thinking it might affect other functions such as mindread.m, or time-transfer-related functions such as doc('who') ... ;-)</description>
		<content:encoded><![CDATA[<p>OK.  I was thinking it might affect other functions such as mindread.m, or time-transfer-related functions such as doc(&#8217;who&#8217;) &#8230; ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20610</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 16 Apr 2008 18:05:02 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20610</guid>
		<description>Tim&#8212;I don't think it affects &lt;tt&gt;bwlabel&lt;/tt&gt;.  I can't speak to the question of "other functions."  :-)</description>
		<content:encoded><![CDATA[<p>Tim&mdash;I don&#8217;t think it affects <tt>bwlabel</tt>.  I can&#8217;t speak to the question of &#8220;other functions.&#8221;  :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Davis</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20592</link>
		<dc:creator>Tim Davis</dc:creator>
		<pubDate>Mon, 14 Apr 2008 23:20:10 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20592</guid>
		<description>dmperm in MATLAB 7.5 or later has been modified, since this article was first written (MATLAB is now using the dmperm in CSparse).  Among other things, dmperm now returns each connected component in their natural order.  That is, p(r(1):r(2)-1) is now [1 2 3 4], not [3 4 2 1], for this example.

There's nothing special to the ordering of nodes within a single connected component, so it makes more sense to return them in a natural order instead of a rather arbitrarily jumbled order.

Does this have any noticeable effect on bwlabel or other functions?</description>
		<content:encoded><![CDATA[<p>dmperm in MATLAB 7.5 or later has been modified, since this article was first written (MATLAB is now using the dmperm in CSparse).  Among other things, dmperm now returns each connected component in their natural order.  That is, p(r(1):r(2)-1) is now [1 2 3 4], not [3 4 2 1], for this example.</p>
<p>There&#8217;s nothing special to the ordering of nodes within a single connected component, so it makes more sense to return them in a natural order instead of a rather arbitrarily jumbled order.</p>
<p>Does this have any noticeable effect on bwlabel or other functions?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20402</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 04 Mar 2008 13:05:32 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20402</guid>
		<description>Ake&#8212;Use &lt;tt&gt;bwlabel&lt;/tt&gt; and &lt;tt&gt;regionprops&lt;/tt&gt;.</description>
		<content:encoded><![CDATA[<p>Ake&mdash;Use <tt>bwlabel</tt> and <tt>regionprops</tt>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ake Lu</title>
		<link>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20397</link>
		<dc:creator>Ake Lu</dc:creator>
		<pubDate>Tue, 04 Mar 2008 03:01:31 +0000</pubDate>
		<guid>http://blogs.mathworks.com/steve/2007/03/20/connected-component-labeling-part-3/#comment-20397</guid>
		<description>Dear Steve,

I would like to count the size of connectors for each "cluster" in the following example
bw =

     0     0     0     0     0     0     1
     0     1     1     0     0     0     1
     0     1     1     0     0     0     0
     0     0     0     1     1     1     0
     0     0     0     1     1     1     0
     0     0     0     0     0     0     0
Then based on  8-connectivity, define 
cluster=
     0     0     0     0     0     0     2
     0     1     1     0     0     0     2
     0     1     1     0     0     0     0
     0     0     0     1     1     1     0
     0     0     0     1     1     1     0
     0     0     0     0     0     0     0
Thus,
cluster one has 10 pixels and   cluster 2= 2 pixels. How could I use the above code to get the size of cluster?

Best regards,

Ake</description>
		<content:encoded><![CDATA[<p>Dear Steve,</p>
<p>I would like to count the size of connectors for each &#8220;cluster&#8221; in the following example<br />
bw =</p>
<p>     0     0     0     0     0     0     1<br />
     0     1     1     0     0     0     1<br />
     0     1     1     0     0     0     0<br />
     0     0     0     1     1     1     0<br />
     0     0     0     1     1     1     0<br />
     0     0     0     0     0     0     0<br />
Then based on  8-connectivity, define<br />
cluster=<br />
     0     0     0     0     0     0     2<br />
     0     1     1     0     0     0     2<br />
     0     1     1     0     0     0     0<br />
     0     0     0     1     1     1     0<br />
     0     0     0     1     1     1     0<br />
     0     0     0     0     0     0     0<br />
Thus,<br />
cluster one has 10 pixels and   cluster 2= 2 pixels. How could I use the above code to get the size of cluster?</p>
<p>Best regards,</p>
<p>Ake</p>
]]></content:encoded>
	</item>
</channel>
</rss>
