-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.py
65 lines (54 loc) · 1.63 KB
/
core.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from imager import Imager
import vars
import os
class Core:
def __init__(self,image):
self.image = image
def DP(self):
print('building dp...')
img = self.image
ET = img.entab
VA = self.image.validPixel
table = [[ (0,0)for i in range(img.vs)] for j in range(img.hs)]
dh = (-1,0,1)
for v in range(img.vs-1,-1,-1):
for h in range(img.hs):
ge = ET[h][v]
mi = vars.inf,0
for sh in (-1,0,1):
if VA((h+sh,v+1)):
tm = table[h+sh][v+1][0]
if tm < mi[0]:
mi = tm,sh
if mi[0] < vars.inf:
table[h][v] = ge+mi[0],mi[1]
return table
def buildseam(self,table):
print('building seam...')
mi = vars.inf,0
for i in range(self.image.hs):
if mi[0] > table[i][0][0]:
mi = table[i][0][0],i
h = mi[1]
li = []
for i in range(0,self.image.vs-1):
try:
li.append(h)
h+= table[h][i][1]
except Exception as e:
print(e,i,h)
quit()
return li
# def test_dp():
# ob = Core(image)
# print('dp...')
# return ob.buildseam(ob.DP())
# x = test_dp()
# def test_colorseam(x):
# for a,b in enumerate(x):
# try:
# image.setPixel((b,a),(255,255,255))
# except Exception as e:
# print(e,b,a)
# image.close()
# test_colorseam(x)