An Automatic Measurement Method for Surface Defects