Resize a photo the ordinary way and you face an ugly trade-off: scale and you squish faces; crop and you lose the edges of the scene. For decades those were the only two options.
In 2007 Shai Avidan and Ariel Shamir published a third way: seam carving. Instead of operating on columns or rectangles, the algorithm finds a seam — a connected path of one pixel per row, winding from the top of the image to the bottom — and removes it entirely. Pick the seam whose pixels are the least visually important, and the image shrinks by one column while the objects that matter stay intact.
Repeat the process — find the cheapest seam, remove it, find the next — and the image can be made arbitrarily narrower without any obvious distortion. The key insight is that the "cheapest seam" problem has optimal substructure: the cheapest path to any pixel on row extends the cheapest path to the best neighbor on row . That is the hallmark of dynamic programming, and it turns what sounds like an exponential search into a single linear-time sweep.
Comments
Loading comments...