KEMBAR78
Seed filling algorithm | PPT
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

Seed filling algorithm

  • 2.
    For highlighting allthe pixels inside the polygon, 2 approaches can be used- 1. Scan Fill 2. Seed Fill (Boundary Fill, Flood Fill )
  • 3.
    Boundary Fill Algorithm Thisalgorithm 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.
  • 4.
    void boundaryfill(int x,inty,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); } }
  • 5.
    Sometimes we wantto 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.
  • 6.
    void floodfill(int x,inty,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); } }
  • 7.
    In brief: ď‚—Flood Filland 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.
  • 8.
    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
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
    4 1 5 23 5 4 3 2 1
  • 18.
  • 19.
    7 8 4 1 23 8 7 4 3 2 1
  • 20.
    11 9 12 710 4 1 2 3 12 11 10 9 7 4 3 2 1
  • 21.
    11 9 7 10 41 2 3 11 10 9 7 4 3 2 1
  • 22.
    9 7 10 4 1 23 10 9 7 4 3 2 1
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 30.
    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