Automatic thresholding has been widely used in the machine vision industry for automated visual inspection of defects. A commonly used thresholding technique, the Otsu method, provides satisfactory results for thresholding an image with a histogram of bimodal distribution. This method, however, fails if the histogram is unimodal or close to unimodal. For defect detection applications, defects can range from no defect to small or large defects, which means that the gray-level distributions range from unimodal to bimodal. For this paper, we revised the Otsu method for selecting optimal threshold values for both unimodal and bimodal distributions, and tested the performance of the revised method, the valley-emphasis method, on common defect detection applications.