Connected-component labeling

For 8-connectivity, meaning considering the diagonals, we Optionally; do another pass to find small islands that, if within a certain range of a larger island, become part of that island? Or just sort them all by length so that if two islands are disconnected by only one tile of water, they become the same island. I'm sure there are many ways to optimize this code, but I'm still happy that it's one of the times I was able to hammer something out just by reading the wikipedia concept summary.

xxxxxx.
xxxxxxxxx.

XXXXXXXXX

xxxxxxxxxxx

xxxxxxxxxxx xxxxxxxxx xx xxxxxxxx xx xxxxxxxxxx xx xxxxxxxxxx xx xxxxxxxxxx xx xxxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxx

    • list
    • list
    • list
figure column.