Overview

The goal of this project is to create a program that enable us to resize images by seam carving. Using Seam Carving we can resize an image and avoid distorting the important content even if it's at the edges (i.e. when cropping would fail)

Plus we can generate really cool animations (click on any description later in the doc)

How Seam Carving works: The Crowd

Let's say we want to shrink this image horizontally

a crowd

First we need to run the input image through an energy function. For my implementation, I used the gradient magnitude function on the grayscale input image.

To do this we take the gray image through an x-derivative sobel filter

And a y-derivative sobel filter

Then combine them: sqrt((xderiv .^ 2) + (yderiv .^ 2)). Now we have the gradient magnitude of the image.

When we have the energy values for each pixel in the image, we find a seam through the energy values. A seam can be thought of as a path through the image one pixel wide that always moves forward and can possibly move only in a one pixel turn each step forward.

This is the first seam for our crowd image overlayed on top of the gradient magnitude image

Since the pixels map one-to-one from our energy-function's output to the original image, this seam still makes sense on the original image. Here is seam overlayed on top of the original image

Now we remove that seam, and repeat until we reach the target size.

Click for animation (WARNING: 37MB)

Finally, we can send the shrunken image to our friends!

More Seam-Carved Successes

For each of these demos, click on the description to get an animation of the seam carving! (warning: super big files)

My parents (shrunk 64px vertically)

before

after



A stargazer (shrunk 100px horizontally)

before

after



A scene from Rugrats (shrunk 100px horizontally)

before

after



A scene from Charlotte airport (shrunk 50px horizontally)

before

after



A puffer fish in the ocean (shrunk 50px vertically)

before

after



Bells and Whistles

Click any description to see animations of the carving for that image!

Also, there is a precompute option to speed up subsequent seam-carves. If you precompute first each seam takes approx. only 0.05s to compute (even if you only remove one seam)!



Where the Seam Carving fails

A Grand-Canyon scene (shrunk 182px horizontally)

This scene almost worked, but towards the end it started to take too many seams from a person, thus distorting him (see second person from the left in this image). The main issue was that there was too much powerful energy everywhere that we had to remove seams from the person.

before

after



A Niagara falls scene (shrunk 100px horizontally)

This scene fails because the people in the image are wearing full blue ponchos so there is not much energy in the body (since it's all around the same color)

before

after



My parents (shrunk 110px horizontally)

This scene fails because the table in front of my parents has very little energy since the colors are very similar (note: the glass is sliced)

before

after






Citations:

stars - https://farm8.staticflickr.com/7117/6985379310_c96d916f85_z.jpg
grand canyon - http://pinkjeeptours.com/grand-canyon/files/2012/07/grand-canyon-splash-image.jpg
rugrats - http://images.wikia.com/rugrats/images/9/92/Rugrats.png
crowd - http://htekidsnews.com/wp-content/uploads/2011/01/613445810_2249c2d193_b.jpg
niagara-falls - http://images.familyvacationcritic.com/niagara-falls-overview.jpg
airport - http://www.visitingdc.com/images/charlotte-airport-address.jpg
fish - https://upload.wikimedia.org/wikipedia/commons/7/77/Puffer_Fish_DSC01257.JPG