Seam Carving in Python
Same image in the gradient domain showing the vertical and horizontal seams of lowest cumulated energy.
The seams of lowest cumulated energy can be seen as the pixels contributing the least to an image. By repeatedly removing or adding seams, it is thus possible to perform “content-aware” image reduction or extension. The resulting images feel more natural, less “streched”.
Height reduced by 50% by seam carving.
Height reduced by 50% by traditional rescaling.
Although seam carving doesn’t need human intervention, in the original paper, a graphical user interface (GUI) was also developed to let the user define areas that can’t be removed, or conversely, that must be removed.
In my opinion, seam carving is simple and elegant. No sophisticated object recognition algorithm was used, yet the results are quite impressive.
You can find my implementation in 250 lines of Python in my git repo:
$ git clone http://www.mblondel.org/code/seam-carving.git
Unfortunately, it’s too slow to be real-time.