We extend our previous work on the image segmentation of electronic structures on patterned wafers to improve the defect detection process on optical inspection tools. Die-to-die wafer inspection is based on the comparison of the same area on two neighboring dies. The dissimilarities between the images are a result of defects in this area of one of the dies. The noise level can vary from one structure to the other, within the same image. Therefore, segmentation is required to create a mask and apply an optimal threshold in each region. Contrast variation on the texture can affect the response of the parameters used for the segmentation. We show a method to anticipate these variations with a limited number of training samples, and modify the classifier accordingly to improve the segmentation results.