Python machine learning for image processing and pattern matching