From the course: Fundamentals of Dynamic Programming
Unlock this course with a free trial
Join today to access over 22,700 courses taught by industry experts.
Solution: Calculating the energy of an image - Python Tutorial
From the course: Fundamentals of Dynamic Programming
Solution: Calculating the energy of an image
- [Instructor] Let's take a look at how the energy calculation is implemented in Python. We're focusing on the file energy.py. First up is the energy_at function. Since the image is represented as a list of lists in Python, we can get the height of the image using the length of the outer list and the width using the length of any of the inner lists. Now, we have to figure out what are the x-coordinates for the pixels to the left and right of the requested pixel. Notice that if the current pixel has an x-coordinate of zero, we can't go to the left and we simply use the current pixel. The same applies if the x-coordinate of the current pixel is all the way to the right of the image. With the x-coordinates of the two surrounding pixels we can take the difference of the red, green, and blue components of these two pixels. The order in which we do the subtraction doesn't matter because we will be squaring the differences anyway.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
What is content-aware image resizing?3m 26s
-
(Locked)
Preprocessing: Defining the energy of an image2m 31s
-
(Locked)
Project: Calculating the energy of an image3m 41s
-
(Locked)
Solution: Calculating the energy of an image2m 20s
-
(Locked)
Using dynamic programming to find low-energy seams3m 31s
-
(Locked)
Project: Finding low-energy seams3m 26s
-
(Locked)
Solution: Finding low-energy seams2m 42s
-
(Locked)
Project: Using backpointers to reconstruct seams3m 50s
-
(Locked)
Solution: Using backpointers to reconstruct seams3m 9s
-
(Locked)
Project: Removing low-energy seams2m 12s
-
(Locked)
Solution: Removing low-energy seams2m 13s
-
-
-