Region Filling: 168 471 Computer Graphics, KKU. Lecture 7 1

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 6

Region Filling

• Seed Fill Approaches


– 2 algorithms: Boundary Fill and Flood Fill
– works at the pixel level
– suitable for interactive painting apllications
• Scanline Fill Approaches
– works at the polygon level
– better performance

168 471 Computer Graphics, KKU. Lecture


1
7
Seed Fill Algorithms: Connectedness
• 4-connected region: From a given pixel, the region
that you can get to by a series of 4 way moves (N, S,
E and W)
• 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)

4-connected 8-connected
168 471 Computer Graphics, KKU. Lecture
2
7
Boundary Fill Algorithm
• Start at a point inside a region
• Paint the interior outward to the edge
• The edge must be specified in a single color
• Fill the 4-connected or 8-connected region
• 4-connected fill is faster, but can have problems:

168 471 Computer Graphics, KKU. Lecture


3
7
Boundary Fill Algorithm (cont.)

void BoundaryFill4(int x, int y,


color newcolor, color edgecolor)
{
int current;
current = ReadPixel(x, y);
if(current != edgecolor && current != newcolor)
{
BoundaryFill4(x+1, y, newcolor, edgecolor);
BoundaryFill4(x-1, y, newcolor, edgecolor);
BoundaryFill4(x, y+1, newcolor, edgecolor);
BoundaryFill4(x, y-1, newcolor, edgecolor);
}
}
168 471 Computer Graphics, KKU. Lecture
4
7
Flood Fill Algorithm
• Used when an area defined with multiple colo
r boundaries
• Start at a point inside a region
• Replace a specified interior color (old color) wi
th fill color
• Fill the 4-connected or 8-connected region un
til all interior points being replaced

168 471 Computer Graphics, KKU. Lecture


5
7
Flood Fill Algorithm (cont.)
void FloodFill4(int x, int y, color newcolor, color oldColor)
{
if(ReadPixel(x, y) == oldColor)
{
FloodFill4(x+1, y, newcolor, oldColor);
FloodFill4(x-1, y, newcolor, oldColor);
FloodFill4(x, y+1, newcolor, oldColor);
FloodFill4(x, y-1, newcolor, oldColor);
}
}

168 471 Computer Graphics, KKU. Lecture


6
7

You might also like