Skip to content

Commit 54545f9

Browse files
author
JeGa
committed
Added file reading.
1 parent c59eaf7 commit 54545f9

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

binseg.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import click
1010
import random
1111

12+
1213
class GMM:
1314
def __init__(self, prob):
1415
"""
@@ -363,7 +364,7 @@ def pairwiseenergy(self, y1, y2, x1, x2):
363364
return energy
364365

365366
def segment(self):
366-
for i in range(1):
367+
for i in range(3):
367368
# For each label: Change current label to alpha?
368369
for alpha in self.label:
369370
self.alpha = alpha
@@ -393,6 +394,19 @@ def getimg(self):
393394
return self.img
394395

395396

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+
396410
def binseg():
397411
logging.info("Read image.")
398412
img = misc.imread("banana3.png")
@@ -416,6 +430,28 @@ def binseg():
416430

417431

418432
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():
419455
logging.info("Read image.")
420456
img = misc.imread("banana3.png")
421457
img = np.array(img, dtype=np.float64) / 255

0 commit comments

Comments
 (0)