1 / 9

Region Filling

Learn about region filling algorithms in computer graphics, including boundary fill and flood fill. These algorithms are used to color in specific image regions and are suitable for interactive painting applications.

cmoyer
Download Presentation

Region Filling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 168 471 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 168 471 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: 168 471 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); } } 168 471 Computer Graphics, KKU. Lecture 7

  5. 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. 168 471 Computer Graphics, KKU. Lecture 7

  6. 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 168 471 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); } } 168 471 Computer Graphics, KKU. Lecture 7

  8. { setcolor(RED); rectangle(100,100,200,200); circle(300,300,50); setfillstyle(1,YELLOW); floodfill(101,101,RED); floodfill(301,301,RED); } 168 471 Computer Graphics, KKU. Lecture 7

  9. 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); 168 471 Computer Graphics, KKU. Lecture 7

More Related