Connected area labeling algorithm