Seam Carving

CS194-26 Image Manipulation and Computational Photography

Jingxi Huang  cs194-26-aap 



Overview

The goal of the project is to implement the seam carving algorithm so that we can resize the image in a content-aware way. To achieve this, the program need to intelligently remove seams from an image and shrink its size. By repeatedly carving out seams with minimum energy path, we can finally remove pixels on that path and output the image that is shrunk either horizontally or vertically to a given dimension.

Implementation

1. The first step of the algorithm is to define an energy function, which will allow us to determine the importance of pixels in the image. For my energy function, I first implemented the Sobel operator to compute the x-gradient and y-gradient by convolving the image with edge detectors. Then, I calculated the sum of the squared gradients to obtain the energy of each pixel in the image.

2. After that, I used Dynamic Programming to find the minimum seam to be removed in the image. I constructed a matrix where each entry is the minimum total energy to that point from the first row of the image. After that, we can find the pixel with minimum total energy on the last row and backtrack to find the minimum seam in the image.

3. Finally, we repeat the process to remove the minimum seam each time until the image is resized to our desired size.

4. To remove the horizontal seam of the image, we can follow the same process by instead transpose the image so that we can use the same algorithm for removing the vertical seam as des

Results

Successful Results

Below are some great examples of resized images. All images are shrinked by 25% in the corresponding dimension.

original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam

Failure Results

Below are some failure results of resized images with distortion or overlap between subjects in the resized image. All images are shrinked by 25% in the corresponding dimension.

original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam
original image
remove vertial seam
remove horizontal seam

What I Learned

The most interesting part I’ve learned from the project is how to determine the importance of pixels in a image and how to remove the least important seam. I also found from failure examples that seam-carving doesn’t work well with faces. It also doesn’t work well when there’s a pattern in the original image, for example, the pattern in the wheeler hall and the pattern on the floor in the third failure example is distorted.