Skip to main content

Flood Fill Algorithm

Flood Fill Algorithm

Flood Fill is a seed fill algorithm similar to Boundary Fill algorithm but sometimes when it is required to fill in an area that is not defined within a single color boundary we use flood fill instead of boundary fill.


This algorithm picks a seed point inside an object and starts to fill until it encounters the boundary of the object. The color of the boundary and the color that we fill should be different for this algorithm to work.

In this algorithm, we assume that color of the boundary is same for the entire object. The boundary fill algorithm can be implemented by 4-connected pixels or 8-connected pixels.




4 Connected Approach:

    In 4-connected technique pixels are used as shown in the figure above. We put the pixels above, below, to the right, and to the left side of the current pixels and this process will continue until we find a boundary with different color.


8 Connected Approach:

    In 8-connected technique pixels are used as shown in the figure above. We put pixels above, below, right and left side of the current pixels as we were doing in 4-connected technique.

In addition to this, we are also putting pixels in diagonals so that entire area of the current pixel is covered. This process will continue until we find a boundary with different color.



Code:

If you can't see the code, then Enable JavaScript in you browser

Output:




Note: Just copy the files "CGA.bgi" &" EGAVGA.bgi" from bgi folder to bin. So, if you have copied these 2 files then you can skip writing "C:\\tc\\bgiin initgraph with just ""(2 double quotes)

Comments

Popular posts from this blog

Bresenham's Line Algorithm (THICK LINE)

Bresenham's Line Algorithm (THICK LINE) Bresenham's Line Algorithm (THICK LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DASHED LINE)

Bresenham's Line Algorithm (DASHED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.

Bresenham's Line Algorithm (DOTTED LINE)

Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) Bresenham's Line Algorithm (DOTTED LINE) The Bresenham algorithm is an incremental scan conversion algorithm.



Bestseller's in Electronics only at Amazon Best Selling Products on Amazon