Connected component labelling implementation