Seed filling algorithm

ManikanthKummarikunt 17,842 views 31 slides May 20, 2018
Slide 1
Slide 1 of 31
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31

About This Presentation

computer graphics


Slide Content

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

14
2
4
2
1

1
2
2
1

51
5
1

1
1

Some region remains unfilled

Start Position
8-connected (Example)

415
2 3
5
4
3
2
1

6
41
2 3
6
4
3
2
1

78
41
2 3
8
7
4
3
2
1

11912
7 10
41
2 3
12
11
10
9
7
4
3
2
1

119
7 10
41
2 3
11
10
9
7
4
3
2
1

9
7 10
41
2 3
10
9
7
4
3
2
1

9
7
41
2 3
9
7
4
3
2
1

7
41
2 3
7
4
3
2
1

41
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
Tags