-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (28 loc) · 789 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import time
from seam_carving import SeamCarving
from PIL import Image
fp = Image.open("hoover.jpeg")
pixels = fp.load()
w, h = fp.size
image_data = [[[0 for k in range(3)] for j in range(w)] for i in range(h)]
for i in range(w):
for j in range(h):
image_data[j][i][0] = pixels[i, j][0]
image_data[j][i][1] = pixels[i, j][1]
image_data[j][i][2] = pixels[i, j][2]
# Call seam carving algorithm passing in the image contents
start = time.time()
sc = SeamCarving()
weight = sc.run(image_data)
print("weight: " + str(weight))
print("seam: " + str(sc.getSeam()))
end = time.time()
print("time: "+ str(end-start))
# Uncomment to display seam on image
seam = sc.getSeam()
y = 0
for x in seam:
fp.putpixel((x,y), 0x000000ff)
y = y+1
fp.show()