Graphcut Writeup

Linda Fong (lfong)
Feb 22, 2010

Algorithm

The purpose of the graphcut project was to take two images, a source image and a target image, and insert the source image into the target with as least noticeable a seam as possible. The problem could be described as trying to cut out a piece of the source image such that the cuts are made where there is least difference between the source and target image. This could be formulated as a min-cut max-flow problem as follows: Each pixel position in the target image is a node in a graph. Each node has an edge to the corresponding nodes for each of the neighboring pixels. Since we want the cut to take place where source and target are most similar to each other, the weight on the edge between two pixels can be defined as the sum of the differences between the target and source images at those two pixel locations.

Also present in a min-cut max-flow problem, is a sink and source node. We define all nodes attached to the source post-cut as the mask for the source image, and all nodes attached to the sink have their pixel values coming from the target. We can define a source_mask, that adds the constraint that all pixels under the source_mask must be attached to the source node (edges to the source node with infinite weight), and all pixels under the target_mask must be attached to the sink node (edges to the sink node with infinite weight).

Implementation Details

Since the input to the graph cut was a source image shifted on a black image the size of the target, there was some finickiness invovled in defining edgeweights where the source image was not meant to exist. All pixels that are not appart of the original source image in this input image are also constrained to be necessarily apart of the target (attached to the sink). This left a little problem where the source image met the target... the edge weights here were zero because the weights set by the above description were only set over the area of contention, in this case that was the location of the source image. The result here was that the image had a tendency to segment along the edge of the source. To fix this the outermost pixels of the source image location were also attached to the target.

Results

This algorithm worked very nicely for the two test cases that came from the paper and not so nicely on the others. In the case of the airplane in the sky, the sky was never really all that similar to the background in color, sometimes the interior of the plane was actually closer, which made for some trouble. A similar case occured for the bear in the water, where the muddy water the bear was in and the blue pool water aren't very similar in color. Not only that but they're pretty uniformly non-similar over most of the image, so there was no particular reason the min cut should choose any one path over another.

I found i got better results when i explicitly defined parts of the image where the source overlayed the target as target. This definitely helped get a closer cut in some of the unhappier cases. To help this selection process, instead of just showing the target when choosing the target map, my implementation allows you to define the target mask from the target image with the source overlayed on top of it in its shifted position.

Results Images