A method of segmenting foreground areas from background areas of an input image including input pixels having grey scale input pixel values, comprising the steps of:
- defining an output image comprising output pixels having binary output pixel values;
- assigning each input pixel and each output pixel a position in a coordinate system so that the input image and the output image correspond to the physical configuration of the substrate;
- assigning a scaling factor to each input pixel so that a scaling factor assigned to an input pixel represents an estimate of the background input pixel values in a neighborhood about the input pixel;
- defining an energy function that varies as a function of the input pixels values, the output pixels values, and the scaling factors comprising
- a first component expressing a cost associated with an output pixel value not being in agreement with the value of a corresponding input pixel taking into account the value of the scaling factor assigned to the corresponding input pixel,
- a second component expressing a cost associated with the value of an output pixel not being in agreement with the values of pixels in a neighborhood around the output pixel, and
- a third component expressing a cost associated with the gradient of the input pixel values so as to define boundaries between regions of the input image having contrasting input pixel values;
- and
- segmenting foreground areas of the output image from background areas of the output image by iteratively varying the output pixel values so that the energy function converges toward a minimum value.