All studies

Dynamic programming

Seam carving

Make an image narrower by removing low-energy paths through it, with painted masks to protect the parts that matter.

JavaScript · Canvas · Web Workers · Dynamic programming

View source on GitHub

Try it

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

All processing stays in your browser. 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
Computed example · run 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.

  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

Outputs from the same implementation used in the playground.

Original landscape photograph used by the algorithm
Landscape photograph · generated input
A landscape made narrower by removing low-energy paths through the photograph
Content-aware reduction · surviving pixels retain their original colors

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.