For highlighting all the pixels inside the polygon,
2 approaches can be used-
1. Scan Fill
2. Seed Fill (Boundary Fill, Flood Fill )
Boundary Fill Algorithm
This algorithm picks a point inside the
polygon and starts to fill until it hits the
boundary of the object.
Assumption:
In this algorithm, we assume that color of the
boundary is same for the entire object.
void boundaryfill(int x,int y,int fill_color,int
boundary_color)
{
if(getpixel(x,y)!=boundary_color &&
getpixel(x,y)!=fill_color)
{
putpixel(x,y,fill_color);
boundaryfill(x+1,y,fill_color,boundary_color);
boundaryfill(x-1,y, fill_color,boundary_color);
boundaryfill(x,y+1, fill_color,boundary_color);
boundaryfill(x,y-1, fill_color,boundary_color);
}
}
Sometimes we want to fill in an area that is
not defined within a single color boundary.
We paint such areas by replacing a specified
interior color instead of searching for a
boundary color value. This approach is
called a flood-fill algorithm.
void floodfill(int x,int y,int fill_color,int old_color)
{
if(getpixel(x,y)==old_color)
{
putpixel(x,y,fill_color);
floodfill(x+1,y,fill_color,old_color);
floodfill(x-1,y, fill_color,old_color);
floodfill(x,y+1, fill_color,old_color);
floodfill(x,y-1, fill_color,old_color);
}
}
In brief:
Flood Fill and Boundary Fill are algorithms used for
coloring a given figure with a chosen color
Flood Fill is one in which all connected pixels of a
selected color get replaced by a fill color.
 Boundary Fill is very similar with the difference being
the program stopping when a given color boundary is
found.
Boundary Fill Algorithm /Flood Fill
algorithm
The boundary fill algorithm/ flood fill algorithm can be
implemented by 4-connected pixels or 8-connected pixels.
4-connected 8-connected
Start Position
4-connected (Example)
3
2
1
1
2 3
1 4
2
4
2
1
1
2
2
1
5 1
5
1
1
1
Some region remains unfilled
Start Position
8-connected (Example)
4 1 5
2 3
5
4
3
2
1
6
4 1
2 3
6
4
3
2
1
7 8
4 1
2 3
8
7
4
3
2
1
11 9 12
7 10
4 1
2 3
12
11
10
9
7
4
3
2
1
11 9
7 10
4 1
2 3
11
10
9
7
4
3
2
1
9
7 10
4 1
2 3
10
9
7
4
3
2
1
9
7
4 1
2 3
9
7
4
3
2
1
7
4 1
2 3
7
4
3
2
1
4 1
2 3
4
3
2
1
1
2 3
3
2
1
1
2
2
1
1
1
Comparison
Flood Fill Algorithm
 Flood fill colors an entire area in an
enclosed figure through
interconnected pixels using a single
color
 So, Flood Fill is one in which all
connected pixels of a selected color
get replaced by a fill color.
 A flood fill may use an
unpredictable amount of memory
to finish because it isn't known how
many sub-fills will be spawned
 Time Consuming
Boundary Fill Algorithm
 Here area gets colored with pixels
of a chosen color as boundary this
giving the technique its name
 Boundary Fill is very similar with
the difference being the program
stopping when a given color
boundary is found.
 Boundary fill is usually more
complicated but it is a linear
algorithm and doesn't require
recursion
 It is less Time Consuming
Seed filling algorithm