File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ def printSeam(sc, direction):
20
20
totalSeamEnergy = sum (sc .energy (col , row ) for col , row in seam_indices )
21
21
print "\n Total seam energy: {:d}" .format (totalSeamEnergy )
22
22
23
- def printVerticalSeamEnergy (sc ):
24
- """vertical seam is a list of cols"""
25
- seam = sc .findVerticalSeam ()
26
- totalSeamEnergy = 0
27
- for row in range (sc .height ()):
28
- for col in range (sc .width ()):
29
- if col == seam [row ]:
30
- totalSeamEnergy += sc .energy (col , row )
31
- print "\n Total seam energy: {:d}" .format (totalSeamEnergy )
23
+ def calculateSeamEnergy (sc , direction ):
24
+ if direction == "vertical" :
25
+ seam = sc .findVerticalSeam ()
26
+ else :
27
+ seam = sc .findHorizontalSeam ()
28
+ relevant_size = sc ._height if direction == "vertical" else sc ._width
29
+ seam_indices = zip (seam , relevant_size )
30
+ totalSeamEnergy = sum (sc .energy (col , row ) for col , row in seam_indices )
31
+ print "\n Total seam energy: {:d}" .format (totalSeamEnergy )
32
+ return totalSeamEnergy
You can’t perform that action at this time.
0 commit comments