Automatic image segmentation for material microstructure characterization by optical microscopy