Skip to content

Commit 337e70f

Browse files
author
JeGa
committed
Added data files.
1 parent 24815b5 commit 337e70f

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

banana3.png

518 KB
Loading

binseg.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import scipy.stats
44
import logging
55
import matplotlib.pyplot as plt
6-
6+
from prettytable import PrettyTable
7+
import progressbar
8+
import maxflow
79

810
class GMM:
911
def __init__(self, prob):
@@ -24,8 +26,17 @@ def prob(self, x):
2426
return prob
2527

2628

27-
def unaryenergy():
28-
pass
29+
def unaryenergy(fg, bg, img):
30+
logging.info("Calculate unary energy functions.")
31+
ysize, xsize, _ = img.shape
32+
unary = np.empty((ysize, xsize, 2))
33+
34+
with progressbar.ProgressBar(max_value=xsize, redirect_stdout=True) as progress:
35+
for x in range(xsize):
36+
for y in range(ysize):
37+
unary[y, x, 0] = -np.log(bg.prob(img[y, x]))
38+
unary[y, x, 1] = -np.log(fg.prob(img[y, x]))
39+
progress.update(x)
2940

3041

3142
def readprobfile(filename):
@@ -51,7 +62,7 @@ def main():
5162
img = misc.imread("banana3.png")
5263
img = np.array(img, dtype=np.float64)
5364

54-
unary = np.empty(img.shape[0:2])
65+
unaryenergy(fg, bg, img)
5566

5667
logging.info("Save image.")
5768
img = img.astype(np.uint8)

prob_background.npz

1.04 KB
Binary file not shown.

prob_foreground.npz

1.04 KB
Binary file not shown.

0 commit comments

Comments
 (0)