Boundary Fill Algorithm
The Boundary Fill Algorithm is a region-filling technique
used to fill a closed area with a specific color until a
boundary color is encountered.
1. Introduction
Boundary fill is used when the boundary of a region is clearly defined with a specific color. The algorithm fills pixels until it reaches this boundary.
- Uses boundary color as stopping condition
- Common in drawing applications
2. Basic Idea
Starting from a seed point inside the region, the algorithm fills neighboring pixels until it encounters the boundary color.
- Seed-based filling
- Stops at boundary color
3. Working Principle
If the current pixel is neither the boundary color nor the fill color, it is filled and its neighbors are processed recursively.
- Checks boundary color
- Uses recursion or stack
4. Types of Boundary Fill
- 4-connected Boundary Fill
- 8-connected Boundary Fill
5. Steps of Boundary Fill Algorithm
- Select a seed point inside the region
- Check pixel color
- Fill pixel if not boundary or fill color
- Recursively process neighbors
6. Boundary Fill Pseudocode
BoundaryFill(x, y, boundaryColor, fillColor):
if color(x, y) == boundaryColor or color(x, y) == fillColor
return
set color(x, y) = fillColor
BoundaryFill(x+1, y)
BoundaryFill(x-1, y)
BoundaryFill(x, y+1)
BoundaryFill(x, y-1)
7. Advantages
- Easy to implement
- Works well for closed boundaries
- Boundary color based control
8. Disadvantages
- Fails if boundary has gaps
- Stack overflow for large regions
- Boundary color must be unique
9. Boundary Fill vs Flood Fill
Boundary Fill Flood Fill ------------------------- ---------------------------- Stops at boundary color Replaces target color Requires boundary defined No boundary required Sensitive to boundary gaps Works on color regions
10. Applications
- Paint programs
- Polygon filling
- Region coloring in graphics
Practice Questions
- What is boundary fill algorithm?
- Explain 4-connected boundary fill.
- Differentiate boundary fill and flood fill.
- Write boundary fill pseudocode.
- List advantages and disadvantages.
Practice Task
Explain with diagram:
✔ Boundary fill working
✔ Boundary vs flood fill
✔ Seed point selection