algorithm with label color detection