Flood and Boundary Fill Algorithm Scan Fill Algorithm
Flood and Boundary Fill Algorithm Scan Fill Algorithm And Antialiasing 4/4/2020 Sandip Tigga, CS, TDC 1
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 4/4/2020 Sandip Tigga, CS, TDC 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 4/4/2020 8 -connected Sandip Tigga, CS, TDC 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 4/4/2020 Sandip Tigga, CS, TDC 4
Boundary Fill Algorithm (cont(. void Boundary. Fill 4(int x, int y , color newcolor, color edgecolor( } int current; current = Read. Pixel(x, y; ( if(current != edgecolor && current != newcolor( } Boundary. Fill 4(x+1, y, newcolor, edgecolor; ( Boundary. Fill 4(x-1, y, newcolor, edgecolor; ( Boundary. Fill 4(x, y+1, newcolor, edgecolor; ( Boundary. Fill 4(x, y-1, newcolor, edgecolor; ( { { 4/4/2020 Sandip Tigga, CS, TDC 5
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 4/4/2020 Sandip Tigga, CS, TDC 6
Flood Fill Algorithm (cont(. void Flood. Fill 4(int x, int y, color newcolor, color old. Color( } if(Read. Pixel(x, y) == old. Color( } Flood. Fill 4(x+1, y, newcolor, old. Color; ( Flood. Fill 4(x-1, y, newcolor, old. Color; ( Flood. Fill 4(x, y+1, newcolor, old. Color; ( Flood. Fill 4(x, y-1, newcolor, old. Color; ( { { 4/4/2020 Sandip Tigga, CS, TDC 7
Polygon Types 4/4/2020 Sandip Tigga, CS, TDC 8
Convex, Concave, Degenerate 4/4/2020 Sandip Tigga, CS, TDC 9
Polygon Representation 4/4/2020 Sandip Tigga, CS, TDC 10
Scanline Fill Algorithm • Intersect scanline with polygon edges • Fill between pairs of intersections • Basic algorithm: For y = ymin to ymax 1) intersect scanline y with each edge 2) sort intersections by increasing x [p 0, p 1, p 2, p 3] 3) fill pairwise (p 0 ->p 1, p 2 ->p 3(… , 4/4/2020 Sandip Tigga, CS, TDC 11
Spacial Handling • Make sure we only fill the interior pixels Define interior: For a given pair of intersection points (Xi, Y), (Xj, Y) -> Fill ceilling(Xi) to floor(Xj) important when we have polygons adjacent to each other. 4/4/2020 Sandip Tigga, CS, TDC 12
Spacial Handling (cont(. • Intersection has an integer X coordinate ->if Xi is integer, we define it to be interior ->if Xj is integer, we define it to be exterior (so don’t fill( 4/4/2020 Sandip Tigga, CS, TDC 13
Spacial Handling (cont(. • Intersection is an edge end point Case 1 Intersection points: (p 0, p 1, p 2? ? ? ( )<-p 0, p 1, p 2) so we can still fill pairwise ->In fact, if we compute the intersection of the scanline with edge e 1 and e 2 separately, we will get the intersection point p 1 twice. Keep both of the p 1. 4/4/2020 Sandip Tigga, CS, TDC 14
Spacial Handling (cont(. Case 2 However, in this case we don’t want to count p 1 twice (p 0, p 1, p 2, p 3), otherwise we will fill pixels between p 1 and p 2, which is wrong. 4/4/2020 Sandip Tigga, CS, TDC 15
Spacial Handling (cont(. Summary: If the intersection is the ymin of the edge’s endpoint, count it. Otherwise, don’t. 4/4/2020 Sandip Tigga, CS, TDC 16
Antialiasing Raster displays have pixels as rectangles Aliasing: Discrete nature of pixels introduces “jaggies” 4/4/2020 Sandip Tigga, CS, TDC 17
Antialiasing • Aliasing effects: Distant objects may disappear entirely Objects can blink on and off in animations Antialiasing techniques involve some form of blurring to reduce contrast, smoothen image • Three antialiasing techniques: Prefiltering Postfiltering Supersampling 4/4/2020 Sandip Tigga, CS, TDC 18
Prefiltering Basic idea: compute area of polygon coverage use proportional intensity value Example: if polygon covers ¼ of the pixel use ¼ polygon color add it to ¾ of adjacent region color Cons: computing pixel coverage can be time consuming 4/4/2020 Sandip Tigga, CS, TDC 19
Supersampling Useful if we can compute color of any (x, y) value on the screen Increase frequency of sampling Instead of (x, y) samples in increments of 1 Sample (x, y) in fractional (e. g. ½) increments Find average of samples Example: Double sampling = increments of ½ = 9 color values averaged for each pixel Average 9 (x, y) values to find pixel color 4/4/2020 Sandip Tigga, CS, TDC 20
Postfiltering • n Supersampling uses average • n Gives all samples equal importance • n Post-filtering: use weighting (different levels of importance( • n Compute pixel value as weighted average • n Samples close to pixel center given more weight 4/4/2020 Sandip Tigga, CS, TDC 21
- Slides: 21