File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ from scipy import misc
3
+ import scipy .stats
4
+ import logging
5
+ import matplotlib .pyplot as plt
6
+
7
+
8
+ class GMM :
9
+ def __init__ (self , prob ):
10
+ self .mu = prob [0 ]
11
+ self .sigma = prob [1 ]
12
+ self .mix = prob [2 ]
13
+
14
+ self .K = self .mu .shape [0 ]
15
+
16
+ self .pdfs = []
17
+ for k in range (self .K ):
18
+ self .pdfs .append (scipy .stats .multivariate_normal (self .mu [k ], self .sigma [k ]))
19
+
20
+ def prob (self , x ):
21
+ prob = 0
22
+ for k in range (self .K ):
23
+ prob += self .mix [k ] * self .pdfs [k ].pdf (x )
24
+ return prob
25
+
26
+
27
+ def unaryenergy ():
28
+ pass
29
+
30
+
31
+ def readprobfile (filename ):
32
+ file = np .load (filename )
33
+ mu = file ["arr_0" ]
34
+ sigma = file ["arr_1" ]
35
+ mix = file ["arr_2" ]
36
+
37
+ return [mu , sigma , mix ]
38
+
39
+
40
+ def main ():
41
+ logging .basicConfig (level = logging .INFO )
42
+
43
+ logging .info ("Read GMM for unaries." )
44
+ probf = readprobfile ("prob_foreground.npz" )
45
+ probb = readprobfile ("prob_background.npz" )
46
+
47
+ fg = GMM (probf )
48
+ bg = GMM (probb )
49
+
50
+ logging .info ("Read image." )
51
+ img = misc .imread ("banana3.png" )
52
+ img = np .array (img , dtype = np .float64 )
53
+
54
+ unary = np .empty (img .shape [0 :2 ])
55
+
56
+ logging .info ("Save image." )
57
+ img = img .astype (np .uint8 )
58
+
59
+ plt .imshow (img )
60
+ plt .show ()
61
+ plt .imsave ("banana_out" , img )
62
+
63
+
64
+ if __name__ == '__main__' :
65
+ main ()
You can’t perform that action at this time.
0 commit comments