Seam Carving for Art-Directed Images
Resize a rights-clear generated poster by removing low-energy seams, painting protection masks, comparing crop and scale, and reporting structural distortion.
Seam carving narrows an image by removing connected low-energy paths, but art direction decides which forms are allowed to bend or disappear. This tutorial uses a generated geometric poster, an explicit protection mask, deterministic dynamic programming, and crop-versus-scale diagnostics to expose every trade-off.
Seam carving makes resize an energy decision
Uniform scaling changes every proportion, and cropping discards a rectangular edge. Seam carving removes a connected path of pixels whose cumulative energy is low, then repeats until the target dimension is reached. The method can preserve salient regions when the image contains expendable low-detail areas, but it can also bend straight lines, duplicate texture, or squeeze faces and symbols.
The original seam-carving paper introduced content-aware resizing through seam removal and insertion. Use the algorithm as a compositional tool, not a universal smart resize. Its energy function sees local signal and masks; it does not understand the semantic importance of an object automatically.
Start with a rights-clear generated image whose geometry you can inspect exactly. The poster here contains a rectangle, a circle, flat color fields, and empty channels. Those shapes make line bending and focal damage visible without importing a photograph or making likeness claims.
The bundled studio draws a visual seam and protection target. Its Node fixture solves a tiny synthetic matrix; neither artifact processes a full production image or claims perceptual quality measurements.
Build an image energy map
Convert the source into a consistent pixel representation and estimate local change. A simple gradient energy combines horizontal and vertical color differences; more elaborate methods can include saliency, edges, entropy, or forward energy that estimates disruption after removal. Document the exact color conversion, boundary handling, kernel, and normalization.
Display the energy map beside the source. High values should align with important edges you expected, while broad flat fields should remain low. If noise or texture dominates, denoise carefully or choose a different signal rather than hiding the problem through arbitrary thresholds.
An image energy map is not an importance map. A smooth face, sky gradient, or logo interior may have low local energy despite high compositional value. That is why protection masks and structural diagnostics remain necessary.
The Hough transform line-art guide offers one way to detect global straight structures. A seam-carving audit can use those lines to measure bending after each removal, even though the seam optimizer itself remains local.
- Base energy marks local image change.
- Protect masks add a deliberate penalty around authored focal forms.
- Remove masks subtract cost only when destruction is intended and reviewed.
| Signal | Interpretation |
|---|---|
| Energy heatmap with protected focal mask | A generated poster's edges glow by gradient energy while a central focal circle receives an explicit protection cost. |
Paint protect and remove masks deliberately
A protected region mask adds cost where seams should avoid a focal shape, text, logo, border, or structural line. A remove mask subtracts cost where disappearance is intentional, such as a generated spacer band. Store both masks separately from the image so their authorship and influence remain reviewable.
Feather mask edges when an abrupt penalty creates visible routing artifacts, but do not feather so broadly that no viable seam remains. Visualize the combined energy after mask application, and report how much each term contributes to the selected path.
Masks can conflict. If a protected subject fills nearly the whole width, the requested target may be impossible without damage. Refuse the target, switch to crop or scale, or ask for another composition instead of allowing enormous penalties to push every seam through one narrow corridor.
The protected region mask in the fixture covers the focal circle while a low-cost vertical channel remains elsewhere. That constructed geometry makes the expected seam deterministic and easy to inspect.
Runnable artifact — The studio renders a generated poster and focal mask, while its deterministic matrix test proves the minimum seam avoids protected cells.
<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Seam carving studio</title><style>body{font:16px system-ui;max-width:800px;margin:2rem auto;padding:1rem;background:#fff8ed;color:#272018}canvas{width:100%;height:auto;border:1px solid #725b46}button{padding:.7rem;margin:.3rem}</style><h1>Seam carving studio</h1><p>Generated geometry only. The focal circle is protected.</p><canvas id="poster" width="640" height="360"></canvas><button id="carve">Remove one visual seam</button><output id="receipt" aria-live="polite"></output><script>const c=poster.getContext('2d');let removed=0;function draw(){c.fillStyle='#17324d';c.fillRect(0,0,640,360);c.fillStyle='#ffbd59';c.fillRect(80,50,120,260);c.fillStyle='#f25f5c';c.beginPath();c.arc(430,180,92,0,Math.PI*2);c.fill();c.strokeStyle='#83f3d3';c.lineWidth=5;c.beginPath();for(let y=0;y<360;y+=12){const x=260+Math.sin(y*.045)*34-removed*3;y?c.lineTo(x,y):c.moveTo(x,y)}c.stroke();receipt.value='PASS: generated poster protects focal mask; seams shown '+removed}carve.onclick=()=>{removed=Math.min(12,removed+1);draw()};draw()</script></html>
Recover vertical seams with dynamic programming
For each pixel row, add local energy to the minimum cumulative cost from reachable pixels in the previous row. Store the chosen predecessor, then backtrack from the smallest cost in the last row to recover one connected top-to-bottom seam. Define tie-breaking so equal-cost paths produce reproducible output.
Boundary pixels need explicit neighbors, and numeric types must tolerate cumulative costs plus mask penalties. Test one-pixel widths, uniform energy, protected columns, alternating minima, and ties. Horizontal resizing can transpose the image or use an analogous left-to-right recurrence.
Remove pixels along the seam and shift each row. Recompute energy near the removed path or recompute the full map for simplicity; stale energy can select paths that no longer reflect the image. Preserve a seam receipt with cost, coordinates, mask intersections, and source revision.
Dynamic programming seams optimize the declared cost exactly for the bounded graph. That mathematical success does not guarantee an aesthetically acceptable resize because the cost function is only a proxy for visible damage.
- Each row stores minimum cumulative cost and a predecessor.
- Backtracking from the last row recovers one connected seam.
- Stable tie-breaking makes the edition reproducible.
| Signal | Interpretation |
|---|---|
| Minimum-seam braid through dynamic-programming rows | Candidate cumulative paths descend through a grid while one selected seam avoids the protected region. |
Audit line, shape, and texture distortion
After each batch, measure the properties your artwork depends on. Straight lines can be fitted before and after to estimate curvature or displacement. Circles and rectangles can be tracked through edge samples. Repeated patterns can be checked for spacing drift, and protected masks can report minimum clearance from removed seams.
Visual inspection remains essential. A low-energy path may create a kink that a simple aggregate misses. Overlay removed seams on the original, animate the sequence optionally, and let the maker scrub to the first unacceptable change.
The optical-flow typography article shows another deformation practice where a field is intentionally applied to letterforms. Seam carving differs because the deformation is an emergent side effect of deletion; typography should usually be protected or regenerated for the target layout.
Set rejection thresholds as edition-specific constraints, not universal perception laws. Archive the diagnostic and the maker's accepted target so later parameter changes can be compared honestly.
Compare crop, scale, and content-aware resizing
Produce the same target size with a centered or art-directed crop, uniform scale, and seam removal. Place them side by side at actual display size and zoom. The best choice may be crop when the edge is expendable, scale when proportions can change slightly, or a redesigned source when every region is important.
Score visible focal retention, line distortion, aspect change, lost content, texture repetition, and mask violations. Keep the method label on every preview. Content-aware resizing should not be sold as automatically more intelligent than simpler operations.
The CSS shape responsive-art guide offers a stronger solution when the source is authored geometry: recompute the composition for the container instead of deforming a raster. Seam carving is most useful when a raster edition must adapt and its expendable channels are real.
The comparison strip deliberately shows different failure silhouettes. It helps the maker choose a method from the artwork rather than from algorithm novelty.
Export an art-directed resize receipt
Save the source generator and seed, original dimensions, target dimensions, energy definition, color space, boundary rule, mask images or vectors, mask weights, tie-breaking, seam coordinates and costs, distortion metrics, software version, and final image digest. Include crop and scale previews when they informed the decision.
Use Canvas 2D with careful pixel and color handling for a browser implementation. Export a compressed raster appropriate to the content, plus a lightweight SVG or HTML diagnostic that overlays seams and mask boundaries without embedding unnecessary source pixels.
Do not imply that a generated protection mask came from semantic recognition. Label it as authored, rule-derived, or model-derived with provenance. The strength of this workflow is that artistic priorities become explicit input rather than invisible post-hoc preference.
If the final poster is printed, inspect it at physical size. Thin line damage and repeated texture can be less forgiving on paper than in a scaled browser preview.
| Method | Primary failure |
|---|---|
| Crop | removes border content |
| Scale | changes all proportions |
| Seam | can bend or repeat structure |
| Signal | Interpretation |
|---|---|
| Crop, scale, and seam comparison strip | Three narrow poster panels expose lost edges, geometric squashing, and seam-induced structure damage under the same target width. |
Stop when the composition asks for redesign
Test empty images, uniform fields, hard diagonals, grids, protected full-width bands, multiple focal masks, noisy texture, extreme targets, seam insertion, and alternating vertical and horizontal removals. Reject invalid dimensions, non-finite energy, mask overflow, and targets with no acceptable path.
The Haar wavelet collage provides an alternative for recomposing detail rather than deleting connected paths. Creative engineering is strongest when the method follows the visual problem instead of forcing every image through one fashionable algorithm.
Seam carving earns its place when the chosen seams travel through genuinely expendable areas and structural metrics remain inside the edition's bounds. When every available path harms a protected form, the correct output is a refusal and a new composition brief.
Open the studio, remove visual seams, then replace the generated poster with another rights-clear geometric source. Paint one protect mask, compare all three resize methods, and archive the first point where the structure becomes unacceptable.
For the synthetic edition, seam carving should report every selected path, the active image energy map, mask penalty, dynamic-programming seam cost, and resulting width. Run the same source through content-aware resizing, crop, and scale at identical dimensions. Add one seam carving rejection case in which the protected region mask spans the viable corridor; the studio should stop rather than draw a flattering but impossible success preview. Preserve that refusal beside the accepted edition as lasting evidence.