1. A method comprising: selecting, by a computing device, a pixel pair including a foreground pixel of an image and a background pixel of the image from a global set of pixels based at least on spatial distances from an unknown pixel and color distances from the unknown pixel, wherein the spatial distances and the color distances are used to calculate costs for pixel pairs with respect to the unknown pixel, the cost for each pixel pair being the sum of a color cost and spatial costs for that pixel pair, and the selecting comprises selecting a pixel pair with a minimum cost; and determining, by the computing device, an opacity measure for the unknown pixel based at least on the selected pixel pair.