Answer the question
In order to leave comments, you need to log in
Why is it taking so long for the depth-first traversal to take place?
I want to make a fill on the image, as in paint. To paint over all pixels of the same color as on the selected one (so far I am comparing only one channel). On a 30*30 image, everything works well.
def dfs_not_recursion(self):
while (self.stack != []):
peak_vertex = self.stack.pop()
if (peak_vertex is not None):
if (not self.is_visited_boolean(peak_vertex)):
self.visited_boolean[peak_vertex.y][peak_vertex.x] = True
if (self.img[peak_vertex.y][peak_vertex.x][0] == self.start_vertex.color[0]):
self.img_draw[peak_vertex.y][peak_vertex.x] = self.GREEN
neighbours = peak_vertex.get_neighbours(self.img)
for i in neighbours:
self.stack.append(i)
Answer the question
In order to leave comments, you need to log in
It's just that paint uses an efficient shading algorithm , and not depth-first crawling.
self.visited_boolean[peak_vertex.y][peak_vertex.x]
This is generally very long, there should be work with raw image lines
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question