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.

2. Basic Idea

Starting from a seed point inside the region, the algorithm fills neighboring pixels until it encounters the 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.

4. Types of Boundary Fill

5. Steps of Boundary Fill Algorithm

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

8. Disadvantages

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

Practice Questions

  1. What is boundary fill algorithm?
  2. Explain 4-connected boundary fill.
  3. Differentiate boundary fill and flood fill.
  4. Write boundary fill pseudocode.
  5. List advantages and disadvantages.

Practice Task

Explain with diagram: ✔ Boundary fill working ✔ Boundary vs flood fill ✔ Seed point selection