This software implements seam carving, a method of content-aware image resizing. The current version is capable of resizing images from 50% width to 150% width using three different cost metrics to compute seams whose insertion or removal causes minimal distortion to the image. The user can also use a painting interface to manually specify regions of high importance--positive cost--so that those regions will not be touched by the resizing algorithm, and regions of low importance--negative cost--so that those regions will be removed by the algorithm. The painting and resizing modes are illustrated in the images below: Here, negative weights (red paint) are used to remove the woman from the photograph, while positive weights (green paint) are used to prevent the rest of the image from becoming distorted.
Different Cost Metrics
The user can select between three different measures of the cost of removing or inserting pixels. The options are Backward Energy, Backward Energy (X direction only), and Forward Energy. The effects are shown on the 50% reductions demonstrated below (performed with no user-supplied weights): Here, the x and y backward energy does a poor job, clearly distorting the image, while the x-only backward energy and forward energy cost metrics do considerably better. However, forward and x-only backward energy do not always outperform regular backward energy as demonstrated on this 50% reduction of an image of a river: For this image, I would argue that the and and y backward energy performs the best because, though it does generate a harder line in the water than forward and x-only backward energy, it retains the shape of the sun, a prominent feature of the image. Both forward energy and x-only backward energy end up squashing the sun, which makes sense because they don't key in on the high vertical contrast through that image region.
This algorithm can also be used to enlarge images, as shown below: For this image, all of the cost metrics produce impressive results.
Displaying Seams
The user can also see the seams that are removed or inserted to reduce or enlarge an image to a specified size. The user simply clicks the "Show Seams" checkbox to toggle seam display. When seams are shown, the image is displayed in its original size, with the pixel paths overlayed in red: The seams that are inserted to produce the enlargment shown at the right are shown on the left.
This program is written in Objective-C using Mac OS X's Cocoa framework. Please be aware that this is by no means polished software, as it was written for a weekly assignment. It has little tolerance for poorly-formed images and could stand considerable tweaking.
Design and code ©2012 Julian Panetta
Valid HTML 4.01 Strict