In the image processing, the dense method is used, that is, the image is processed by the pixel collection. In the image topology aspect, the graph computation method is applied more.
To find a Java version of the non-graph Unicom subset, code:
Finds all connected subsets of undirected graphs//wishchin ... public static arraylist<set<integer>> findallcons (Boolean adjm[][]) {arraylist<set<integer>
> consets = new arraylist<set<integer>> ();
stack<integer> tree = new stack<integer> ();
boolean[] IsTra = new Boolean[adjm.length];
for (int i = 0; i < adjm.length ++i) {Istra[i] = (false); //Traverse each line for (int i = 0; i < adjm.length;)
{if (istra[i] = = true) {++i;
Continue
} tree.push (i);
set<integer> sub = new hashset<integer> ();
Sub.add (i);
Int J = Tree.peek ();
while (!tree.isempty () && istra[j] = = False) {j = Tree.pop ();//Remove stack top I istra[j] = true; Traverse each column for (int k = 0; k < adjm[j].length ++k) {if (false = Istra[k]) {if (adjm[j][k] = = True &am
p;& Istra[k] = = False) {Tree.push (k);//If K has not been traversed, then press into Stack Sub.add (k);
}} j = Tree.peek ();
} ++i;
Consets.add (sub); }
return consets; }
Precautions:
In Java, the set class is an abstract class that cannot be instantiated directly, and a subclass of set must be instantiated, such as HashSet.