Skip to content

Commit 05696bb

Browse files
author
aprameya2001
committed
refactored
1 parent dd6f314 commit 05696bb

14 files changed

+19
-5
lines changed

Images/col1.jpg

13.4 KB
Loading

Images/col2.png

35.1 KB
Loading

Images/col3.jpg

7.2 KB
Loading

Images/col4.jpg

18.3 KB
Loading

Images/col5.jpg

30.8 KB
Loading

Images/col6.jpg

22.4 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

imageInput.py renamed to driver.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
import cv2
33
import time
4+
import shutil
45
import argparse
56
import subprocess
67
import numpy as np
8+
import matplotlib.pyplot as plt
79

810
FRG, BKG = "FRG", "BKG"
911
FRGCODE, BKGCODE = 1, 2
@@ -52,9 +54,9 @@ def paintSeeds(self, pixelType):
5254
def imageInput(self, imagefile, size):
5355

5456
pathname = os.path.splitext(imagefile)[0]
55-
imageOrg = cv2.imread(imagefile, cv2.IMREAD_GRAYSCALE)
5657

57-
self.image = cv2.cvtColor(imageOrg, cv2.COLOR_GRAY2RGB)
58+
self.image = cv2.imread(imagefile)
59+
imageOrg = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)
5860
self.seeds = np.zeros(imageOrg.shape, dtype="uint8")
5961

6062
sfx, sfy = imageOrg.shape[0] / size[0], imageOrg.shape[1] / size[1]
@@ -174,11 +176,22 @@ def getForeground(self, algo="fordFulkerson"):
174176

175177
return algo, list(map(int, genData)), runtime
176178

179+
def createBarPlot(self, algos, runtimes):
180+
plt.bar(algos, runtimes, width = 0.4)
181+
plt.xlabel('Algorithms used')
182+
plt.ylabel('Runtime')
183+
plt.title('Execution times of different algorithms for Binary Image Segmentation')
184+
plt.savefig('./Results/plot.jpg')
185+
177186
def displayResults(self, sf, size, imagefile):
178187

179188
algos = ["fordFulkerson", "edmondKarp", "scaling", "dinic"]
189+
runtimes = []
180190

181-
subprocess.Popen(["mkdir", "-p", "Results"])
191+
directory = './Results'
192+
if os.path.exists(directory):
193+
shutil.rmtree(directory)
194+
os.makedirs(directory)
182195

183196
file = open("./Results/results.txt", "w")
184197

@@ -205,9 +218,10 @@ def displayResults(self, sf, size, imagefile):
205218
)
206219

207220
file.write(str(round(runtime, 5)) + "\n")
221+
runtimes.append(runtime)
208222

209223
file.close()
210-
224+
self.createBarPlot(algos, runtimes)
211225
subprocess.Popen(["python3", "gui2.py"])
212226

213227

gui2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def displayOutputInCanvas():
5252
cv2.imread("./Results/edmondKarp.jpg"),
5353
cv2.imread("./Results/scaling.jpg"),
5454
cv2.imread("./Results/dinic.jpg"),
55-
cv2.imread("./Results/image.jpg"),
55+
cv2.imread("./Results/plot.jpg"),
5656
]
5757

5858
titleList = [

0 commit comments

Comments
 (0)