Visual depiction of the local thresholding approach.

If the intensity at a pixel (x, y) differs from the mean intensity inside the window by more than some pre-defined threshold, we conclude that it is a foreground pixel.