File Exchange

image thumbnail

find_components

version 1.1 (9.61 KB) by

finds the connected components of an image

3 Downloads

Updated

View License

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 at http://www.suitesparse.com.

Comments and Ratings (7)

My hero, exactly what I have been boggeling my mind over. Good work!!!!

Oliver Woodford

Works well, and very efficient. Many thanks.

Thomas Clark

Thomas Clark (view profile)

Thanks Tim!

This is very popular in the current ML contest (flooding a matrix with colour, Fall 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.

Kenneth Eaton

Kenneth Eaton (view profile)

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

John D'Errico

John D'Errico (view profile)

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

Updates

1.1

Converted to a toolbox. Minor update to the example.

MATLAB Release
MATLAB 7.6 (R2008a)
Acknowledgements

Inspired: ISLANDS

MATLAB Online Live Editor Challenge

Win cash prizes and have your live script featured on our website

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video