Polygon Filling
Polygon Filling
Polygon filling is the process of "coloring in" a definite image area or region. Polygon may be
defined at the pixel or geometric level.
Seed Fill Approaches
– 2 algorithms: Boundary Fill and Flood Fill
– better performance
• 8-connected region: From a given pixel, the region that you can get to by a series of 8 way
moves (N, S, E, W, NE, NW, SE, and SW)
int current;
If (Get pixel x, y) < > fill and Get Pixel (x, y) < > boundary) then
End of Procedure
• Fill the 4-connected or 8-connected region until all interior points being replaced
{
if(ReadPixel(x, y) == oldColor)
Stack-based approach
Following is the boundary fill algorithm using 4-connected fill method. It is a stacked-based approach with
fill color specified by ‘fill’ and boundary color specified by ‘boundary’.
or
Boundary fill using 4-connected fill method
PUSH pixel(x, y)
if (Get pixel (x +1, y) < > fill and Get pixel (x +,y) < > boundary) then
If Get pixel(x - 1, y) < >fill and get pixel (x - 1, y) < > boundary) then
If Get pixel(x, y + 1) < >fill and get pixel (x, y + 1) < > boundary) then
If Get pixel(x, y -1) < >fill and get pixel (x ,y -1) < > boundary) then
end of while
->In fact, if we compute the intersection of the scanline with edge e1 and e2 separately, we will get the
intersection point p1 twice. Keep both of the p1.
However, in this case we don’t want to count p1 twice (p0,p1,p1,p2,p3), otherwise we will fill pixels
between p1 and p2, which is wrong
Summary: If the intersection is the ymin of the edge’s endpoint, count it. Otherwise, don’t.
1). A seed pixel located on the scan line within the area popped from a stack
containing the seed pixel is selected.
2). The line or span containing the seed pixel is filled to its right and left including
the seed pixel itself until the boundary is found.
3). The extreme left and extreme right unprocessed pixel in the span are saved as
x-left & x-right, respectively.
4). The scan line above and below the current scan line are examined in the range
x-left and x-right for any simple crossover. The extreme right pixel in all the
unfilled spans on these scan lines within the same range is marked as a seed pixel
and pushed onto the stack.
The Seed Fill Algorithms assume that at least one pixel is interior to a polygon or region is known. The
algorithm then attempts to find and color or fill all other pixels interior to the region.
Or
Input : Pixel (x,y) as the seed pixel, fill as fill color and boundary as boundary colour
save y = y
x = x +1
setpixel (x,y,fill) : Fill the span to the right of the seed pixel
x = x+1
end while
xright = x – 1 : Save the extreme right pixel of the span in the current scan line
Set pixel (x,y, fill) : fill the span to the left of the seed pixel
x=x–1
end while
xleft = x +1 : Save the extreme left pixel of the span in the current xcan line
x = xleft, y = save y + 1
x = x+1
else
while (Get pixel (x,y) <> boundary and Get pixel (x,y) <> fill and x <= x right)
x=x+1 : find the extreme right pixel of each unfilled span and
push it onto the stack
end while
Push pixel (x – 1, y)
x = x+1
end if
end while
end while
end while