From the course: Fundamentals of Dynamic Programming

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Solution: Finding low-energy seams

Solution: Finding low-energy seams - Python Tutorial

From the course: Fundamentals of Dynamic Programming

Solution: Finding low-energy seams

- [Instructor] Let's look at how you would implement the seam finding algorithm in Python. We're going to focus on the file seam_v1.py. The only function we needed to implement was compute vertical seam V one. The first thing we'll do in this function is create a grid to store the values of the M function. The grid has the same size and shape as the input grid of energy values. But we can initialize all the values as zero. Next, we can extract the height and width of the image based on the grid of energy values. The first thing we have to do is fill out the top row. Here, we could just copy over the energy values from the top row, exactly as our base case is defined. Now, we can loop through each element of the grid of energy values. Remember, this grid corresponds one-to-one with the pixels of the original image. Because we primarily care about X and Y coordinates of each pixel, we use the range function in Python…

Contents