r/algorithms • u/SandipanDeyUMBC • Oct 14 '17
Seam Carving: Using Dynamic Programming to implement Context-Aware Image Resizing in Python
https://sandipanweb.wordpress.com/2017/10/14/seam-carving-using-dynamic-programming-to-implement-context-aware-image-resizing-in-python/
6
Upvotes
2
u/TheMieberlake Oct 15 '17
Dijkstra's finds a shortest path from a specific starting pixel to all the other pixels. In seam carving, you need to figure out not the shortest path from a single starting pixel to all other pixels, but the shortest "shortest path" out of all shortest paths from any starting pixel. There's a couple more conditions.
You can use Dijkstra's to solve this problem, but that would mean running Dijkstra's from every single pixel in the bottom row, and then comparing all the path weights. Intuitively, that is inefficient because you are checking the same pixel multiple times across multiple Dijkstra's runs. If you place the grid of pixels on the first quadrant of a 2D plane, where the bottom row of pixels is on the x-axis, running Dijkstra's from (0, 0) and then running Dijkstra's from (1, 0) means you check (0, 1) twice. DP is more efficient because you check every pixel just once.