Pattern recognition in defect detection