Basically you need to define mostX, mostY, smallestX and smallestY.
Find the bottom right corner of the real edge:
You can do this by going as far right as possible + down inside your color.
If you can no longer go right + down, you need to check to make sure that you are not stuck in the corner of the island. To make sure of this, you need to follow around the edge, looking for a chance to go even more to the right + down. You can track (largest, largest, smallest, smallest) every time this happens, if you really have a real edge.
If you actually have an island, you will eventually find a place beyond the edge that you can go further on the right + down.
If you have no chance to go even further + down, and you will reach your starting point, then you have a real edge. And you calculated yours (the largest, largest, smallest and smallest).
source share