Cropping an image is typically limited to selecting rectangular portions of an image and removing them. Enlarging an image typically means stretching an image which can result in pixelation. Seam Carving, also known as Liquid Resizing is a technique that removes both of these limitations.
Seam carving works by finding the low-energy seams of the image and then removing vertical or horizontal (but not necessarily straight) seams from the image. In this context low-energy seams are single-pixel wide parts of the image where there is not much change. Because the seams occur in areas where there is not much change, their removal is less likely to be noticed.
For this implementation I created a program that uses a Sobel filter to determine low-energy seams in the input image. These seams are marked with red in the featured images accompanying this post.
The technique can also be used to increase image size, essentially by working in reverse. The idea is to identify seams that would have been removed and then insert seams in those locations as again, these seems are unlikely to be noticed.
In the last series of featured images newly added seams are marked in green. The color of the added seams in the final image is calculated by averaging the color of pixels on either side of the image. This is known as “seam insertion” and its usefulness is one reason “Liquid Resizing” could be a better name for this general algorithm.
This project implements the academic paper Region Filling and Object Removal by Exemplar-Based Image Inpainting by Shai Avidan and Ariel Shamir.