Polygon Fill Method: Seed Filling: Boundary fill and Flood fill algorithm

Seed Filling: In this method a particular seed point is picked and we start filling upwards and downwards pixels until boundary is reached. Seed fill method is of two types: Boundary fill and Flood fill.

Boundary fill algorithm: In Boundary filling a seed point is fixed, and then neighboring pixels are checked to match with the boundary color. Then, color filling is done until boundary is reached. A region may be 4 connected or 8 connected:

4 connected and 8 connected region in boundary fill algorithm

Procedure for filling a 4- connected region: Color is specified by parameter fill color (f-color) and boundary color is specified by boundary color (b-color). getpixel() function gives the color of specified pixel and putpixel() fills the pixel with particular color.

boundary_ fill (x,y, f_color, b_color)

{

If  ( getpixel (x,y) != b_color &&  getpixel (x,y) != f_color)

putpixel(x,y,f_color)

boundary_fill( x+1, y, f_color, b_color);

boundary_fill( x, y+1, f_color, b_color);

boundary_fill( x-1, y, f_color, b_color);

boundary_fill( x, y-1, f_color, b_color);

}

}

Flood fill algorithm: There are some cases where the boundary color is different than the fill color. For situations like these Flood fill algorithm is used. Here the process is started in a similar way by examining the colors of neighboring pixels. But instead of matching it with a boundary color a specified color is matched.

Procedure for filling a 8- connected region:

flood_ fill (x,y, old_color, new_color)

{

putpixel(x,y,new_color)

flood_ fill (x+1, y, old_color, new_color)

flood_ fill (x-1, y, old_color, new_color)

flood_ fill (x, y+1, old_color, new_color)

flood_ fill (x, y-1, old_color, new_color)

flood_ fill (x+1, y+1, old_color, new_color)

flood_ fill (x-1, y-1, old_color, new_color)

flood_ fill (x+1, y-1, old_color, new_color)

flood_ fill (x-1, y+1, old_color, new_color)

}

}

Disadvantages of Seed Fill Algorithm:

1) If an inside pixel is in some other color then the fill terminates and the polygon remains unfilled.

2) Seed fill method does not work for large polygons.

Leave a Reply