Pattern Recognition as a Consistent Labeling Problem