An apparatus for classifying defect codes associated with defects on a substrate, the substrate including a plurality of dies, comprising:means for determining an average density of defects on the substrate; means for selecting a defect of interest; means for determining a local density of defects in a selected area surrounding the defect of interest; means for defining a search area around the de