Two-Stage Automated Defect Recognition Algorithm for the Analysis of Infrared Images