0
895views
Write the algorithm for filling polygons and explain it with a suitable example.

Write the algorithm for filling polygons and explain it with a suitable example.

1 Answer
0
32views


Filling is the process of ‘coloring in’ a fixed area or region. Following are the various algorithm used to fill the area :-

  1. Boundary-fill algorithm :

    a. An approach to area filling is to start at a point inside a region and point the interior outward toward boundary.

    b. If the boundary is specified in a single color, the fill algorithm proceeds outward pixel by pixel until the boundary color is encountered.

    c. It is particularly useful in interactive painting packages, where interior points are easily selected.

    d. A boundary fill procedure accepts as input the coordinates of an interior points (x, y) a fill color, and a boundary color.

    e. The following procedure illustrate a recursive method for filling 4-connected with an intensity specified in parameter fill up to boundary specified with parameter boundary.


Procedure boundaryfill4 (x, y, fill, boundary : integer);
var
current : integer;
begin
current = getpixel (x, y);
if (current != boundary) and (current != fill) then
begin
setpixel(x, y, fill);
boundaryfill4 (x + 1, y, fill, boundary);
boundaryfill4 (x – 1, y, fill, boundary);
boundaryfill4 (x, y + 1, fill, boundary);
boundaryfill4 (x, y – 1, fill boundary);
end;



  1. Flood-fill algorithm :

    a. It is used to fill the area that is not defined within a single color boundary.

    b. We can paint such areas by replacing a specified interior color.

    c. We start from a specified interior point (x, y) and reassign all pixels values that are currently set to a given interior color with the desired fill color.

    d. The following procedure flood fills a 4-connected region recursively, starting from the input position.


Procedure floodfill4(x, y, fillcolor, oldcolor : integer);
begin
if (getpixel(x, y) = oldcolor) then
begin
setpixel(x, y, fillcolor);
floodfill4 (x+1, y, fillcolor, oldcolor);
floodfill4 (x–1, y, fillcolor, oldcolor);
floodfill4 (x, y+1, fillcolor, oldcolor);
floodfill4 (x, y–1, fillcolor, oldcolor);
end;
end;
Please log in to add an answer.