An elementary algorithm for classifying digital objects based on the variational principle