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)
Let's say we want to shrink this image horizontally
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!
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
before
after
before
after
before
after
before
after
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)!
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
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
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: