Albedo
Albedo

Reputation: 11

Seam Carving compute cost in one loop in python

How to compute the energy cost for Seam Carving in one loop iterating through the rows for python? Seam Carving Wiki Like the Dynamic programming in wiki ,I need the min_cost on the last row for possible three cell, and store the cost and path.

And , it is very slow by using two loop , so anyone know how to make it more efficiently?

Upvotes: 1

Views: 172

Answers (1)

rikyeah
rikyeah

Reputation: 2013

You can use numba.jit to (possibly) speed up calculations, provided you respect the correct typing. There is no way to avoid 2 loops in a dynamic programming, however you can take a look at improved seam carving (which also yields better results in general)

https://github.com/axu2/improved-seam-carving https://medium.com/@avik.das/improved-seam-carving-with-forward-energy-88ba84dab7e

from numba import jit 

@jit
def calc_seam(img):
   ...

Upvotes: 0

Related Questions