Automatic Detection and Classification of Rock Microstructures through Machine Learning