The study of microstructures for the accurate control of material properties is of industrial relevance. Identification and characterization of microstructural properties by manual measurement are often slow, labour intensive, and have a lack of repeatability. In the present work, the intermetallic phase ratio and grain size in the microstructure of known Mg-Sn-Al alloys were measured by computer vision (CV) technology. New Mg (Magnesium) alloys with different alloying element contents were selected as the work materials. Mg alloys (Mg-Al-Sn) were produced using the hot-pressing powder metallurgy technique. The alloys were sintered at 620 °C under 50 MPa pressure in an argon gas atmosphere. Scanning electron microscopy (SEM) images were taken for all the fabricated alloys (three alloys: Mg-7Al-5Sn, Mg-8Al-5Sn, Mg-9Al-5Sn). From the SEM images, the grain size was counted manually and automatically with the application of CV technology. The obtained results were evaluated by correcting automated grain counting procedures with manual measurements. The accuracy of the automated counting technique for determining the grain count exceeded 92% compared to the manual counting procedure. In addition, ASTM (American Society for Testing and Materials) grain sizes were accurately calculated (approximately 99% accuracy) according to the determined grain counts in the SEM images. Hence, a successful approach was proposed by calculating the ASTM grain sizes of each alloy with respect to manual and automated counting methods. The intermetallic phases (Mg17Al12 and Mg2Sn) were also detected by theoretical calculations and automated measurements. The accuracy of automated measurements for Mg17Al12 and Mg2Sn intermetallic phases were over 95% and 97%, respectively. The proposed automatic image processing technique can be used as a tool to track and analyse the grain and intermetallic phases of the microstructure of other alloys such as AZ31 and AZ91 magnesium alloys, aluminium, titanium, and Co alloys.