Let us assume we have the following 2d array:
2 1 2 2 1 1
2 2 1 2 1 1
2 1 3 2 1 1
2 2 2 1 3 3
2 2 1 1 3 3
2 2 1 1 3 3
Now, I want to find contiguous regions in the above. Two locations belong to a contiguous region if there is a path between them and their values are the same. Moreover, all nodes in the path should also have the same value. For example, We can divide the above into the following 5 regions:
A B A A D D
A A B A D D
A B C A D D
A A A D E E
A A D D E E
A A D D E E
You are allowed to go in all 8 directions. I am looking for an implementation in Java. Can someone please help me with this. The interface is something like
VectorFeature returnComp(int matrix[][])
where VectorFeature can be as follows
class VectorFeature{
string region
int numberForRegion
int numOfElements
}
I Know the idea of how to implement this but i am looking for a fast/ bug free implementation in JAVA!