Apex › Data & encoding

How content-aware resize works (seam carving)

Resize an image without distorting it: instead of cropping edges or squishing everyone thin, delete the pixels that matter least. Each pixel gets an energy (gradient magnitude); the least-energy connected seam (one pixel per row) is found by dynamic programming — M[r][c] = energy + min of the three above — and removed, repeatedly, so the picture narrows while the sun and tower stay intact. Verified in node: the DP’s min-seam equals a brute-force search over 400 grids (0 mismatch). It’s Photoshop’s Content-Aware Scale, and the same min-path DP as Viterbi and edit distance. Drag to remove seams and toggle the energy view.

More in Data & encoding