All studies

Dynamic programming

Seam carving

Narrow a balloon landscape by removing connected paths of pixels. Compare it with a regular resize and protect the balloons from the seam search.

JavaScript · Canvas · Web Workers · Dynamic programming

View source on GitHub

Try it

Runs locally in your browser. Uploaded images stay on your device.

Image uploads are resized to a 384px preview.

Paint on the source to protect a subject or mark an area for removal. Green protects; coral attracts seams. Keyboard: focus the source and use arrows to move and paint.

Source image
Source image
Precomputed Seam carving example
Example · update to make your own

Ready when you are.

Worker processing · local inputs · downloadable output

How it works

Paint on the source to protect a subject or mark an area for removal. Green protects; coral attracts seams. Keyboard: focus the source and use arrows to move and paint.

A regular resize compresses every column equally. Seam carving changes the image’s width by removing connected paths through less costly regions. The balloons are protected in this example so the search favors the surrounding sky and landscape.

  1. Measure local image gradients to build an energy map.
  2. Use dynamic programming to find the lowest-energy connected top-to-bottom seam.
  3. Remove it, update the image and masks, then find the next seam.

Read the original research
Shai Avidan & Ariel Shamir · 2007

Computed examples

The regular resize and carved result have the same width. The mask shows which subjects the seam search protects.

Original · hot-air balloon landscape
Regular resize · every column compressed equally
Seam carving · lower-cost paths removed around the subjects
Protection mask · green regions discourage seam removal

Source photographs were generated for these studies. The displayed results were computed by the algorithms; they are not generated illustrations of an expected result. Published previews are compressed for the web.

Implementation and limits

Uses backward gradient energy and removes vertical seams. Large changes can bend straight lines or distort faces; a protection mask cannot guarantee an undistorted result.

Interactive settings are bounded to keep the experiment practical in a browser. Higher detail can cost more processing time without guaranteeing a better result. The implementation and its tests are available in the source repository.

Protect and remove brushes affect the seam cost. Masks shrink with the image after every removal. If a protected region blocks every possible seam, some protected pixels must still be removed.