Boundary Fill Algorithm in Computer Graphics

Boundary Fill Algorithm:

In Computer Graphics, To fill a boundary-defined area is to start at a point (pixel) inside the area and paint the area progressively towards the boundary. This method is called Boundary Fill Algorithm. The Boundary Fill is a recursive procedure with a fill colour. It is specified by the parameter ‘fill‘ and boundary colour specified by parameter ‘boundary‘. Boundary Fill Algorithm is generally two types of methods:

i. 4-connected: In this approach, firstly there is a selection of the interior pixel which is inside the boundary then about that pixel, the adjacent pixel will be filled up which is top-bottom and left-right.

ii. 8-connected: It is the best way of filling the colour correction in the interior of the area defined. This is used to fill in more complex figures. In this four diagonal pixels are also included with a reference interior pixel.

Area Filling:

So far as area filling is concerned we can identify two types of areas or regions:
i. Interior-defined: An Interior-defined region is a collection or patch of the same colour contiguous pixels. Pixels exterior to the region have different colours.

Boundary-Fill-Algorithm-in-Computer-Graphics

ii. Boundary-defined: A boundary-defined region pixels that mark the boundary or outline of the region. It has a unique colour that isn’t the same as the colour of the interior pixels. This procedure accepts as input the coordinates of a sample pixel called the Seed-Pixel. The Seed-Pixel is first set to fill colour while its neighbouring pixels are examined for boundary colour. If boundary colour isn’t found then these pixels are set to fill colour.

Steps of Boundary Fill Algorithm:

[c]Algorithm BoundaryFill4(x, y, boundary_Color, fill_Color)
{
Color=get_Color(x,y);
if(Color<>boundary_Color and Color<>fill_Color)
then
SetPixel(x, y, fill_Color);
BoundaryFill4(x, y+1, boundary_Color, fill_Color);
BoundaryFill4(x-1, y, boundary_Color, fill_Color);
BoundaryFill4(x, y-1, boundary_Color, fill_Color);
BoundaryFill4(x+1, y, boundary_Color, fill_Color);
Endif
}
[/c]

Advantages of Boundary Fill Algorithm:
1. This method is good for a polygon with a multicolour area and single-coloured boundary.

2. In this method, pixels may be visited more than once.

Disadvantages of Boundary Fill Algorithm:
1. It may not fill regions correctly if the same interior pixels also displayed in fill colour.

2. In the 4-connected approach, there is a problem. Sometimes it does not fill the corner pixel as it checks only the adjacent position of the given pixel.