Python Forum
need help with floodfill - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: need help with floodfill (/thread-19514.html)



need help with floodfill - rfdv - Jul-02-2019

Hello, i'm having some difficulty at a college task and I wonder if you can help me. It is the realization of a floodfill algorithm in python 3 using the queue structure in an array of any dimension. I was following this tutorial, but I do not quite understand what that color of node is. But I know that i have to use pop and append on lines 5 and 8.

Floodfill_with_queue (image, node, target_color, replacement_color):
1. If target_color is equal to replacement_color, return image.
2. If color of node is not equal to target_color, return image.
3. Set the color of node to replacement_color.
4. Set Q to the empty queue.
5. Add node to the end of Q.
6. While Q is not empty:
7. Set n equal to the first element of Q.
8. Remove first element from Q.
9. If the color of the node to the west of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
10. If the color of the node to the east of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
11. If the color of the node to the north of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
12. If the color of the node to the south of n is target_color,
set the color of that node to replacement_color and add that node to the end of Q.
13. Continue looping until Q is exhausted.
14. Return image.


RE: need help with floodfill - perfringo - Jul-03-2019

Without effort from your side there will be no help.

Write code according to algorithm and do it as much as you can. Put comment in places where you don't know what to write and then return with your code and specific question.

Something along those lines:

def floodfill_with_queue (image, node, target_color, replacement_color):
    if target_color == replacement_color:
        return image
    /.../