Skip to content

Commit 6cb15f1

Browse files
committed
A3 Q3
1 parent f275b3c commit 6cb15f1

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
30.2 KB
Loading

Assignment-3/Q3.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ def __init__(self, image, seedPoint, tolerance):
102102
self.Result = np.copy(image)
103103
self.SeedBGR = [image[seedPoint[0], seedPoint[1], 0], image[seedPoint[0], seedPoint[1], 1], image[seedPoint[0], seedPoint[1], 2]]
104104

105+
def checkPoints(self, point):
106+
if point[0] >= self.Result.shape[0] or point[0] < 0:
107+
return 0
108+
if point[1] >= self.Result.shape[1] or point[1] < 0:
109+
return 0
110+
if not self.Visited[point[0]-1, point[1]] == 1:
111+
return 1
112+
if not self.Visited[point[0]+1, point[1]] == 1:
113+
return 1
114+
if not self.Visited[point[0], point[1]-1] == 1:
115+
return 1
116+
if not self.Visited[point[0], point[1]+1] == 1:
117+
return 1
118+
119+
105120
def run(self, point):
106121
if point[0] >= self.Result.shape[0] or point[0] < 0:
107122
return
@@ -123,10 +138,14 @@ def run(self, point):
123138
self.Result[point[0], point[1], 1] = 0
124139
self.Result[point[0], point[1], 2] = 0
125140
self.Visited[point[0], point[1]] = 1
126-
self.run([point[0]-1, point[1]])
127-
self.run([point[0]+1, point[1]])
128-
self.run([point[0], point[1]-1])
129-
self.run([point[0], point[1]+1])
141+
if self.checkPoints([point[0]-1, point[1]]) == 1:
142+
self.run([point[0]-1, point[1]])
143+
if self.checkPoints([point[0]+1, point[1]]) == 1:
144+
self.run([point[0]+1, point[1]])
145+
if self.checkPoints([point[0], point[1]-1]) == 1:
146+
self.run([point[0], point[1]-1])
147+
if self.checkPoints([point[0], point[1]+1]) == 1:
148+
self.run([point[0], point[1]+1])
130149

131150
def ShowResults(self, filename):
132151
cv2.imwrite(filename, self.Result)

0 commit comments

Comments
 (0)