3
3
import scipy .stats
4
4
import logging
5
5
import matplotlib .pyplot as plt
6
-
6
+ from prettytable import PrettyTable
7
+ import progressbar
8
+ import maxflow
7
9
8
10
class GMM :
9
11
def __init__ (self , prob ):
@@ -24,8 +26,17 @@ def prob(self, x):
24
26
return prob
25
27
26
28
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 )
29
40
30
41
31
42
def readprobfile (filename ):
@@ -51,7 +62,7 @@ def main():
51
62
img = misc .imread ("banana3.png" )
52
63
img = np .array (img , dtype = np .float64 )
53
64
54
- unary = np . empty ( img . shape [ 0 : 2 ] )
65
+ unaryenergy ( fg , bg , img )
55
66
56
67
logging .info ("Save image." )
57
68
img = img .astype (np .uint8 )
0 commit comments