1. A method for segmenting an image comprising pixels, the method comprising: generating a background mask corresponding to pixels that have been identified as background pixels in the image; generating an edge mask corresponding to pixels that have been identified as edge pixels in the image; dilating the edge mask; generating a refined edge mask by performing the steps comprising: responsive to a dilated edge pixel from the edge mask not satisfying any criterion from a set of darkness criteria, removing the dilated edge pixel from the edge mask; responsive to an edge pixel from the edge mask that is also assigned a background label in the background mask, removing the edge pixel from the edge mask; and responsive to a color value of an edge pixel from the edge mask being brighter by a threshold than a color value of at least one edge pixel from a neighborhood of the edge pixel, removing the edge pixel from the edge mask; and using the refined edge mask to generate a foreground mask.