Optional Part: Seam Carving
Seam carving allows one to retarget an image, or change the aspect ratio, while preserving important content. Please read Sections 3-4.1 from the Seam Carving paper.
Your assignment is to implement a seam carving algorithm that will retarget an image horizontally from an initial size w x h to have a smaller size w' x h. Note this same algorithm can also retarget an image vertically simply by transposing the input. Optional extra credit: you can also implement enlarging the image and doing simultaneous retargeting in both horizontal and vertical directions (see Sections 4.2-4.).
The first step of seam carving is to compute an energy map e, as shown here:
We suggest to use the same energy map as in the paper which takes the L1 norm of the image gradient (you can convert the image to grayscale for this step):
The second step is to implement a function that finds the path of an optimal vertical seam through the image. To check your work, you can visualize this seam to verify that it passes through an area of low energy. This is the same dynamic programming problem as in image quilting.
The final step is to implement a function
remove_vertical_seam that takes an input image, finds the optimal seam, and removes it, returning an image one smaller in width. You can repeatedly apply this function to implement the full seam carving, by iterating until the target width w' is reached.
For the optional part, place a subdirectory
part2 in your submission zip file containing:
- Source for a program that allows seam carving to be run. This should take arguments of an input image, an output image, and a target width w'.
- Add to your README writeup a brief text documentation of how to run the program.
- Choose a fun image. Save the input (
input.png) and your result after retargeting the width by a factor of 80% and 50% (
output_50.png). We will look at some student results in class.