Partition a map of water flows
Mathematica

The basin size list can be gotten by

WatershedComponents[
 Image[Rest@ImportString[m,"Table"]] // ImageAdjust,
 CornerNeighbors -&gt; False,
 Method -&gt; "Basins"
 ] // Reverse@Sort@Part[Tally[Flatten@#], All, 2] &amp;


where m is the given input data. To display a matrix like the ones in the question one can replace // Reverse@Sort@Part[Tally[Flatten@#], All, 2] &amp; with /. {1 -&gt; "A", 2 -&gt; "B", 3 -&gt; "C"} // MatrixForm or one can display it as an image instead using //ImageAdjust//Image.