Quality control with defect detection