Flood fill

According to wikipedia: Flood fill also called Seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array. It is used in the “bucket” fill tool of paint programs to determine which parts of a bitmap to fill with color, and in games such as Go and Minesweeper for determining which pieces are cleared. When applied on an image to fill a particular bounded area with color, it is also known as boundary fill.

I implemented it in python using pygame. The algorithm used is the depth-first algorithm(recursive). In my flood fill program, for every pixel filled, the functions analyze neighbor pixels: 4 neighbors (except diagonal neighbors); this kind of connectivity is called 4-connectivity. The code of this section is shown below:

 

 The complete code is available in  https://bitbucket.org/vidyakv/flood-fill-using-pygame/changeset/bf1a8df717ea . The following images are the snapshots taken during flood filling.
                                

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: