1. A computer-implemented method for segmenting pixels in an image of a wafer for defect detection, comprising: determining a statistic for individual pixels based on a characteristic of the individual pixels in an image acquired for a wafer by an inspection system; assigning the individual pixels to first segments based on the statistic; detecting one or more edges between the first segments in an image of the first segments; generating an edge map by projecting the one or more edges across an area corresponding to the image for the wafer; and assigning the individual pixels to second segments by applying the first segments and the edge map to the image for the wafer thereby segmenting the image, wherein defect detection is performed based on the second segments to which the individual pixels are assigned, and wherein steps of the method are performed by a computer system.