Machine learning based histogram matching for pattern recognition