We describe an algorithm, Contour Area Filtering, for separating background from foreground in gray scale images. The algorithm is based on the area contained within gray scale contour lines. It can be viewed as a form of local thresholding, or as a seed growing algorithm, or as a type of watershed segmentation. The most important feature of the algorithm is that it uses object area to determine the segmentation. Thus, it is relatively impervious to brightness and contrast variations across an image or between different images. Contour Area Filtering was designed specifically for image analysis of 2D electrophoresis gels, although it can be applied to other gray scale images. A typical gel image is an electrophoretogram or a phosphor image of 1000-2500 spots representing protein or DNA restriction fragments. The images are quantitative with spot intensities reflective of the number of proteins or the DNA fragment copy number. The background intensity can vary widely across the image caused both by variation in spot density and by the physical laboratory process of creating a gel. Analyzing and comparing gel images entails extracting and segmenting spots, registering images and matching spots, and measuring differences between spots. We present experimental results which show that Contour Area Filtering is a quick, efficient method for separating electrophoresis gel background from foreground with extremely high accuracy.