Flood Fill Algorithm

Timeline: Oct 2019

I did this project for UBC’s CPSC 221 course. The detailed description of this project can be found here, and my code for this project can be found here.

In this project, I implemented a flood fill algorithm in C++ that performs BFS and DFS traversal of coordinates in an image, starting from a randomly generated set of center coordinates. The algorithm colors each coordinate visited in the image, either using BFS or DFS traversal, based on the color of its closest neighbouring center coordinate. I also implemented function objects to determine the color of each pixel, and stack, queue, and deque structures to store the pixels for the BFS and DFS fills. The end result is the same image filled with different patterns (using the different function objects), and using BFS or DFS traversals. Check out how different the BFS and DFS fills of the same original image look, and see if you can make sense of why they look the way they do!:)

BFS fill: BFS fill

DFS fill: DFS fill

Gökçe Dilek
Gökçe Dilek
Software Engineer & Open Source Contributor

Related