Optimal labeling problems are NP-hard in many practically important cases. Sufficient conditions for optimal label detection in every pixel are formulated. Knowing the values of the optimal labeling in some pixels, as a result of applying the proposed algorithm, allows to decrease the complexity of the original problem essentially.