This fun little project was inspired by a forum post for the Coursera course Discrete Inference and Learning in Artificial Vision.
I use the method outlined in Graphcut Textures: Image and Video Synthesis Using Graph Cuts.
The toy problem is as follows. Given two images overlaid on top of each, with say a 50% overlap, find the best seam cut through the top most image to produce the best “blended” looking image. No actual alpha blending is performed though!
This is a task that can be done physically with two photos and a pair of scissors.
The problem is illustrated with the example below. Here the second image I want to blend with is a duplicate of the first image. The aim is to find a suitable seam cut in the top image such that when I merge the two images it produces the smoothest transition. This may seem unintuitive without alpha blending but it possible depending on the image, not all type of images will work with this method.
By formulating the problem as a graph cut problem we get the following result.
and the actual seam cut in thin red line. You might have to squint.
If you look closely you’ll see some strangeness at the seam, it’s not perfect. But from a distance it’s pretty convincing.
Here are a more examples using the same method as above, that is: duplicate the input image, shift by 50% in the x direction, find the seam cut in the top layer image.
This one is very realistic.
Who likes penguins?
You’ll need OpenCV 2.x install.
I’ve also included the maxflow library from http://vision.csd.uwo.ca/code/ for convenience.
To run call
$ ./SeamCut img.jpg