Avidan & Shamir · SIGGRAPH 2007
Seam carving — the 2007 algorithm, interactively
Upload a photo and watch seam carving work in real time: the live preview shows the image shrinking or expanding as low-energy seams are removed or inserted, one pass at a time. Useful for learning how the algorithm behaves on different scenes.
How does seam carving work?
Seam carving is a content-aware image resizing algorithm introduced by Shai Avidan and Ariel Shamir at SIGGRAPH 2007. The key insight is that not all pixels in an image are equally important. By computing an energy map — typically the gradient magnitude at each pixel — the algorithm can distinguish between high-energy regions (edges, faces, text, sharp transitions) and low-energy regions (smooth gradients, sky, uniform backgrounds).
A seam is a connected path of pixels running from one edge of the image to the other (top to bottom for vertical seams, left to right for horizontal seams), where each pixel in the path is adjacent to or diagonally adjacent to the next. The algorithm uses dynamic programming to find the seam with the lowest total energy — the path that passes through the least visually important pixels in the image.
To shrink an image by one pixel in width, the algorithm removes the lowest-energy vertical seam. Repeating this process removes multiple seams, progressively narrowing the image while preserving high-energy content. To expand an image, the process is reversed: the lowest-energy seams are identified and then duplicated (the seam pixels are inserted alongside their neighbors), adding width to low-information areas while leaving important content untouched.
The energy function
The quality of seam carving depends heavily on the energy function used to evaluate pixel importance. The most common approach computes the gradient magnitude using the Sobel operator or a simple forward difference: for each pixel, measure how much its color differs from its neighbors. Large differences (edges) produce high energy; small differences (smooth areas) produce low energy. This implementation also supports face detection as an additional energy source — detected faces receive a high energy boost, ensuring seams route around them even if the surrounding skin tones have low gradient energy.
When does seam carving fail?
Seam carving works best when an image has clear regions of low and high importance. It struggles in specific scenarios:
- Repeating patterns (brick walls, tiled floors, fabric textures) — seams can disrupt the regularity of the pattern, creating visible artifacts where tiles or bricks appear misaligned.
- Faces near edges — if a face is at the very edge of the image and the resize requires significant expansion or removal in that direction, even face detection may not fully prevent distortion.
- Extreme aspect ratio changes — removing or adding more than 30-40% of the width or height starts to produce visible artifacts in most images, as the algorithm runs out of low-energy seams and begins cutting through meaningful content.
- High-detail images with no clear background — dense scenes where every region has high energy (crowded streets, complex nature close-ups) leave the algorithm no good seams to remove.
For these edge cases, a combination of content-aware scaling with traditional cropping or manual masking typically produces better results. This tool defaults to PNG output format to preserve quality for cases where you want to inspect the result closely before final use.
Curious what happens when you push the algorithm past its limits on purpose? The content aware scale video generator animates the carving process frame by frame and exports it as an MP4 or GIF — the classic melting-image meme effect.