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:
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.
My hero, exactly what I have been boggeling my mind over. Good work!!!!
Works well, and very efficient. Many thanks.
This is very popular in the current ML contest (flooding a matrix with colour, Fall 2009).
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.
Professionally written. Excellent help. Internal comments that can teach everyone on the FEX something about how to write code.
Converted to a toolbox. Minor update to the example.
Nice example, better plotting.