File Exchange

image thumbnail

find_components

version 1.1 (9.61 KB) by Tim Davis
finds the connected components of an image

1 Download

Updated 20 Nov 2014

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.

Cite As

Tim Davis (2019). find_components (https://www.mathworks.com/matlabcentral/fileexchange/21366-find_components), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

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

Works well, and very efficient. Many thanks.

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.

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

John D'Errico

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.

1.0.0.0

Nice example, better plotting.

MATLAB Release Compatibility
Created with R2008a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: ISLANDS