forked from sellaziz/compi-graph-cut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
29 lines (23 loc) · 727 Bytes
/
test.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
from PIL.Image import open
from main import *
from Img2Graph import *
import matplotlib.pyplot as plt
# Create a simple image
img = np.zeros((3,3))
img[:2,:2] = 1
# Prior
O = [(0,0)] # Prior Object - Source S
B = [(2,2)] # Prior Background - Sink T
priors = (O,B)
# WIDTH, HEIGHT = 50,50
# img = np.array(open('images\dog.jpg').convert('L').resize((WIDTH, HEIGHT)))/255
# img_painted = np.array(open('images\dog_ST.jpg').resize((WIDTH, HEIGHT)))
# priors = initialize_priors(img_painted)
G,_ = image2graph(img, *priors, nbins=10, prior_as_index=True)
seg = graph2img(segment(G), *img.shape)
plt.figure(figsize=(15,7))
plt.subplot(121)
plt.imshow(img, cmap='gray')
plt.subplot(122)
plt.imshow(seg, cmap='gray')
plt.show()