9
9
import click
10
10
import random
11
11
12
+
12
13
class GMM :
13
14
def __init__ (self , prob ):
14
15
"""
@@ -363,7 +364,7 @@ def pairwiseenergy(self, y1, y2, x1, x2):
363
364
return energy
364
365
365
366
def segment (self ):
366
- for i in range (1 ):
367
+ for i in range (3 ):
367
368
# For each label: Change current label to alpha?
368
369
for alpha in self .label :
369
370
self .alpha = alpha
@@ -393,6 +394,19 @@ def getimg(self):
393
394
return self .img
394
395
395
396
397
+ def loadunaryfile (filename , ysize , xsize , labels ):
398
+ data = np .empty ((ysize , xsize , labels ))
399
+ file = open ("filename" , "r" )
400
+ for y in range (ysize ):
401
+ for x in range (xsize ):
402
+ line = file .readline ()
403
+ strdata = line .split ("," )
404
+ floatdata = []
405
+ for i in strdata :
406
+ floatdata .append (float (i ))
407
+ data [y , x ] = floatdata
408
+
409
+
396
410
def binseg ():
397
411
logging .info ("Read image." )
398
412
img = misc .imread ("banana3.png" )
@@ -416,6 +430,28 @@ def binseg():
416
430
417
431
418
432
def alphaexp ():
433
+ imagename = ""
434
+ unaryfilename = ""
435
+
436
+ logging .info ("Read image." )
437
+ img = misc .imread (imagename )
438
+ img = np .array (img , dtype = np .float64 ) / 255
439
+
440
+ logging .info ("Load unaries." ) #
441
+ unaries = loadunaryfile (unaryfilename , img .shape [0 ], img .shape [1 ], 21 )
442
+
443
+ binseg = BinsegAlphaexp (img , unaries , 21 )
444
+ binseg .segment ()
445
+
446
+ logging .info ("Save image." )
447
+ img = binseg .getimg ().astype (np .uint8 )
448
+
449
+ plt .imshow (img )
450
+ plt .show ()
451
+ plt .imsave ("banana_out" , img )
452
+
453
+
454
+ def alphaexpbinary ():
419
455
logging .info ("Read image." )
420
456
img = misc .imread ("banana3.png" )
421
457
img = np .array (img , dtype = np .float64 ) / 255
0 commit comments