Download presentation
Presentation is loading. Please wait.
1
168 471 Computer Graphics, KKU. Lecture 7
Region Filling Region Filling is the process of “coloring in” a definite image area or region. Seed Fill Approaches 2 algorithms: Boundary Fill and Flood Fill works at the pixel level suitable for interactive painting applications Computer Graphics, KKU. Lecture 7
2
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 Computer Graphics, KKU. Lecture 7
3
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: Computer Graphics, KKU. Lecture 7
4
Boundary Fill Algorithm (cont.)
void BoundaryFill4(int x, int y, int fill, int Boundary) { int current; current = ReadPixel(x, y); if(current != Boundary && current != 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); } Computer Graphics, KKU. Lecture 7
5
168 471 Computer Graphics, KKU. Lecture 7
Recursive Boundary fill algorithms may not fill regions correctly if some interior pixels are already displayed in the fill color. This occurs because the algorithms checks next pixels both for boundary color and fill color. Encountering a pixel with the fill color can cause a recursive branch to terminate, leaving other interior pixels unfilled. To avoid this we can first change the color of any interior pixels that are initially set to fill color before applying boundary fill procedure. Computer Graphics, KKU. Lecture 7
6
168 471 Computer Graphics, KKU. Lecture 7
Flood Fill Algorithm Used when an area defined with multiple color boundaries Start at a point inside a region Replace a specified interior color (old color) with fill color Fill the 4-connected or 8-connected region until all interior points being replaced Computer Graphics, KKU. Lecture 7
7
Flood Fill Algorithm (cont.)
void FloodFill4(int x, int y, int fillcolor, int oldColor) { if(ReadPixel(x, y) == oldColor) FloodFill4(x+1, y, fillcolor, oldColor); FloodFill4(x-1, y, fillcolor, oldColor); FloodFill4(x, y+1, fillcolor, oldColor); FloodFill4(x, y-1, fillcolor, oldColor); } Computer Graphics, KKU. Lecture 7
8
168 471 Computer Graphics, KKU. Lecture 7
{ setcolor(RED); rectangle(100,100,200,200); circle(300,300,50); setfillstyle(1,YELLOW); floodfill(101,101,RED); floodfill(301,301,RED); } Computer Graphics, KKU. Lecture 7
9
168 471 Computer Graphics, KKU. Lecture 7
Setfillstyle Purpose: setfillstyle is used to set the color and style to be filled in the object using the flood fill method. Syntax: stefillstyle(STYLE, COLOR); Example: setfillstyle(1,RED) Floodfill Purpose: floodfill function is used to fill the color in the object, object may be circle, rectangle or any other closed image. Syntax: floodfill(x,y,boundary color); Example: floodfill(100,100,BLUE); Computer Graphics, KKU. Lecture 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.