Seam Carving

Introduction

There are many different ways to resize an image, including rescaling and cropping. However, these methods all come with a certain flaw to them: they typically do not preserve visually salient objects within an image. Seam carving, as described in this paper, is a way to reduce the size of an image, while being able to retain key objects within the image.

The Implementation

The main idea of seam carving is to repeatedly find a 'seam' within an image, and continuously remove it until the image is reduced to the targeted size. A seam can be thought of as the lowest cost path from one edge of an image to its opposing edge. This path is calculated using an energy map, which can be calculated from the image in a variety of ways. Within my implementation, I decided to use a derivative filter to calculate the energy map. However, other heuristics can also be used, with differing results.

The Results

I started off my testing process with a picture that I took at Eagle Lake on my most recent trip to Lake Tahoe. Below are the results of resizing it using the above algorithm. On the left is the original image. On the right is the resized version.

I took the below image on the UC Berkeley campus. The resized version is to its right.

I took the below image in a recent trip to Lake Tahoe. The resized version is to its right.

The following images are images sourced from the internet. Their resized versions are to the right.

I also tried using the algorithm on a scene found in digital animation, with surprisingly good results.

The Failures

Not everything was perfect on the first try. What I noticed that didn't work perfectly, or as expected were images that contained objects that had objects that are expected to have a certain shape. The example failure cases that I provide below are of portrait shots that I took in the past.

A more extreme case can be seen below.

Conclusion

From implementing this myself, I realized that even simple ideas can be extremely powerful. It doesn't take thousands of lines of code in order to provide an equally impressive result.