PadhaikoAll subjects

Past exam question: 2081 Chaitra (Regular), Q2(b)

Computer Graphics and Visualization · 3 marks

Open in the Padhaiko app

Topic: Scan-Line, Boundary & Flood Fill

Question

Differentiate between boundary fill and flood fill Algorithm.

Solution

Conceptual Differences Between Boundary-Fill and Flood-Fill: Both algorithms are seed-based, recursive/stack area-filling techniques used to color interior regions of polygons and closed curves in raster displays, but they rely on fundamentally different termination conditions:

Comparison CriterionBoundary-Fill AlgorithmFlood-Fill Algorithm
Basic ConceptFills an enclosed area outward from an interior seed point until reaching a specified single boundary color.Replaces all connected pixels of an old interior color (target color) with a new fill color.
Termination ConditionTests if current pixel color is equal to boundary_color OR already colored with fill_color.Tests if current pixel color is NOT equal to old_color OR already colored with fill_color.
Boundary RequirementRequires a continuous, closed boundary composed of a single, uniform color. If the boundary is broken or multicolored, color leaks out.Does not require a distinct boundary color. Can fill regions bounded by multiple different colors, provided the interior has a uniform original color.
Typical Input ParametersboundaryFill(x, y, fillColor, boundaryColor)floodFill(x, y, newColor, oldColor)
Application DomainInteractive graphics where user defines an outline with a specific stroke color.Paint programs ("paint bucket" tool) where an existing colored patch or background needs recoloring.

Algorithmic Structure Comparison: Both algorithms can be implemented using 4-connected (orthogonal neighbors) or 8-connected (including diagonals) recursion:

Boundary-Fill Procedure:

procedure BoundaryFill4(x, y, fillColor, boundaryColor):
    current = getPixel(x, y)
    if (current != boundaryColor and current != fillColor):
        setPixel(x, y, fillColor)
        BoundaryFill4(x + 1, y, fillColor, boundaryColor)
        BoundaryFill4(x - 1, y, fillColor, boundaryColor)
        BoundaryFill4(x, y + 1, fillColor, boundaryColor)
        BoundaryFill4(x, y - 1, fillColor, boundaryColor)

Flood-Fill Procedure:

procedure FloodFill4(x, y, newColor, oldColor):
    current = getPixel(x, y)
    if (current == oldColor and current != newColor):
        setPixel(x, y, newColor)
        FloodFill4(x + 1, y, newColor, oldColor)
        FloodFill4(x - 1, y, newColor, oldColor)
        FloodFill4(x, y + 1, newColor, oldColor)
        FloodFill4(x, y - 1, newColor, oldColor)
Answer:

Boundary-fill fills outward until encountering a predefined boundary color (requiring a single-color closed perimeter), whereas flood-fill tests the interior color and replaces a designated old color with a new color across connected pixels, making it capable of filling regions bounded by multi-colored edges.

All past exam questions for Computer Graphics and Visualization