Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
472 views

To Implement Boundary Fill Algorithm

Boundary fill is an algorithm used to color figures in computer graphics by filling an area with a chosen color up to a boundary. It works by recursively filling pixels starting from a seed pixel until it reaches the boundary color. There are 4-connected and 8-connected boundary fill algorithms, which differ in whether they consider diagonal neighboring pixels when filling. The 4-connected algorithm only fills horizontally and vertically adjacent pixels, while the 8-connected algorithm also fills diagonally adjacent pixels to correctly fill more complex shapes. Pseudocode is provided for both the 4-connected and 8-connected boundary fill algorithms.

Uploaded by

SanjayLulla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
472 views

To Implement Boundary Fill Algorithm

Boundary fill is an algorithm used to color figures in computer graphics by filling an area with a chosen color up to a boundary. It works by recursively filling pixels starting from a seed pixel until it reaches the boundary color. There are 4-connected and 8-connected boundary fill algorithms, which differ in whether they consider diagonal neighboring pixels when filling. The 4-connected algorithm only fills horizontally and vertically adjacent pixels, while the 8-connected algorithm also fills diagonally adjacent pixels to correctly fill more complex shapes. Pseudocode is provided for both the 4-connected and 8-connected boundary fill algorithms.

Uploaded by

SanjayLulla
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

To

Implement
Algorithm

Boundary

Fill

Boundary Fill is algorithm used for the purpose of coloring figures in


computer graphics. It is so similar to Flood Fill that many are confused as to
whether it is another variation of it. Here area gets colored with pixels of a
chosen color as boundary this giving the technique its name. One can see
the difference in the conditions that are there for planting the seeds.
Boundary fill fills the chosen area with a color until the given colored
boundary is found. This algorithm is also recursive in nature as the function
returns when the pixel to be colored is the boundary color or is already the
fill color.
If the boundary is specified in a single color, the fill algorithm proceeds
outward pixel-by-pixel until the boundary color is encountered. This is
called boundary fill algorithm.

4-Connected Region

Figure shows two methods for proceeding to neighbouring pixels from the
current test position. In the figure, four neighbouring points are tested.
The four neighbouring sides are refered as:
1.
2.
3.
4.

North
East
West
South

These are the pixel positions that are right, left above, and below the current
pixel. Areas filled by this method are called 4-connected. It is called 4-

connected because it is connected to 4 neighbouring regions of the current


pixel.

8-Connected Region

The second method, shown in figure is used to fill more complex figures.
Here the set of neighbouring positions to be tested includes the four
diagonal pixels. Fill methods using this approach are called 8-connected.
The eight neighbouring sides are refered as:
1.
2.
3.
4.
5.
6.
7.
8.

North
East
West
South
North-East
North-West
South-East
South-West

An 8-connected boundary fill algorithm would correctly fill the interior of


the area defined in figure but the 4 connected boundary fill algorithm
produces partial fill shown.

Algorithm for 4-connected boundary fill :


void boundaryFill4 (int x, int y, int fill, int boundary)
{
int current;
current = getPixel (x, y);
if ((current != boundary) && (current != fill))
{
setColor (fill);

setPixel (x, y);


boundaryFill4 (x+1, y, fill, boundary);
boundaryFill4 (x-1, y, fill, boundary);
boundaryFill4 (x, y+1, fill, boundary);
boundaryFill4 (x, y-1, fill, boundary);
}}

Algorithm for 8-connected boundary fill :


void boundaryFill8 (int x, int y, int fill, int boundary)
{
int current;
current = getPixel (x, y);
if ((current != boundary) && (current != fill))
{
setColor (fill);
setPixel (x, y);
boundaryFill8 (x+1, y, fill, boundary);
boundaryFill8 (x-1, y, fill, boundary);
boundaryFill8 (x, y+1, fill, boundary);
boundaryFill8 (x, y-1, fill, boundary);
boundaryFill8 (x+1, y+1, fill, boundary);
boundaryFill8 (x-1, y-1, fill, boundary);
boundaryFill8 (x-1, y+1, fill, boundary);
boundaryFill8 (x+1, y-1, fill, boundary);
}
}

Conclusion:

You might also like