CS129 / Project 3 / Seam Carving

Example of a boat after seam carving.


  1. Introduction:

    Image Retargeting is a very important technology in computer vision and photography. Image retargeting should be 'aware' of the important content of the image. To do automatic image retargeting, seam carving is good choice. In this project I generate a program that can find the optimal seams and remove them to generate better scale that preserves the important results.

  2. Algorithm:

    2-1. Generate energy table:

    Define E(I) = |dI/dx|+|dI/dy|, I can calculate the energy by doing this: for every 'r','g','b' value of the image, on position(x,y), calculate the abs(2*P(x)-P(x-1)-P(x+1))+abs(2*P(y)-P(y-1)-P(y+1)), and if the position is on the borders, than the coefficient of the P(x), P(y) may be changed and the pixel that do not exist is not estimated. Than, using dynamic programming to generate the M[] table, which M[i,j] = E(i,j)+min(M(i-1,j-1), M(i-1,j),M(i-1,j+1));

    2-2. Back track and find the best ones:

    What I need to do here is to find the least energy in the last row and begin to back track the rout along each row forward. If the index in the former row is on the edge(i.e. The index in the former row is 1 or width), they do not have certain up-wards neighbors , and should be considered separately.

    2-3. Remove the seams:

    Using the table generated, we can remove the seams by looking up the seam table according to certain number and remove them one by one.

  3. Experiment Result:

Results in a table

Original Image

Vertical Seams

Horizontal Seams

Seam Carving in Vertical

Seam Carving in Horizontal




























My own test case:








Failure Cases:






As is shown above, the vertical seam caving's result is not good because human eyes are sensitive to the 'Sawtooth' on a straight line. The seam carving in vertical on this test case generates a lot of 'sawtooth' on the plant, which makes the result 'unrealistic'.