5.0

5.0 | 5 ratings Rate this file 31 downloads (last 30 days) File Size: 10.38 KB File ID: #21366

find_components

by Tim Davis

 

07 Sep 2008 (Updated 09 Sep 2008)

Code covered by the BSD License  

finds the connected components of an image

Download Now | Watch this File

File Information
Description

find_components finds the connected components of an image. Two pixels are in the same component if they are adjacent (north, south, east, or west, but not NW, SW, etc) and have the same value.

This was a bit of recreational weekend programming, in reply to Doug Hull's Puzzler of Aug. 18, 2008:

http://blogs.mathworks.com/pick/2008/08/18/puzzler-find-largest-connected-island/

It also serves as a nice example of DMPERM. To read more about dmperm, and to read its code, see CSparse or CXSparse on the File Exchange.

Acknowledgements
This submission has inspired the following:
ISLANDS
MATLAB release MATLAB 7.6 (R2008a)
Other requirements Your results will vary if you use MATLAB 7.4 or earlier; DMPERM was upgraded for MATLAB 7.5.
Zip File Content  
Other Files find_components/Contents.m,
find_components/find_components.m,
find_components/find_components.png,
find_components/find_components_example.m,
find_components/largest_component.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
30 Oct 2008 John D'Errico

Professionally written. Excellent help. Internal comments that can teach everyone on the FEX something about how to write code.

30 Oct 2008 Kenneth Eaton

I hadn't ever happened upon DMPERM before. Thanks for pointing out something new, Tim.

18 Feb 2009 Ben Petschel

Nice code Tim. I hadn't come across DMPERM before either.

The variables K, East, South aren't really needed because K(E)=E, K(S)=S, East(E)=E+m, South(S)=S+1, and E & S can be defined without K.

07 Nov 2009 Thomas Clark

Thanks Tim!

This is very popular in the current ML contest (flooding a matrix with colour, Fall 2009).

12 Feb 2010 Oliver Woodford

Works well, and very efficient. Many thanks.

Please login to add a comment or rating.
Updates
09 Sep 2008

Nice example, better plotting.

Tag Activity for this File
Tag Applied By Date/Time
morphology Tim Davis 22 Oct 2008 10:18:10
segmentation Tim Davis 22 Oct 2008 10:18:10
image Tim Davis 22 Oct 2008 10:18:10
connected components Tim Davis 22 Oct 2008 10:18:10
dmperm Tim Davis 22 Oct 2008 10:18:10
puzzler Tim Davis 22 Oct 2008 10:18:10

Contact us at files@mathworks.com