3. 3
Contents
• Polygon filling algorithms
• Seed Fill Algorithm
• Boundary Fill Algorithm
• Flood Fill Algorithm
• Scan Line Algorithm
4. Introduction
Scan conversion
• One way to designing raster system is having separate display coprocessor(display
processor/ graphics controller).
• Purpose of display processor is to free CPU from graphics work.
• Display processors have their own separate memory for fast operation.
• Main work of display processor is digitalizing a picture definition given in an
application program into a set of pixel intensity values for storage in frame
buffer.
• This digitalization process is scan conversion.
• Graphics commands specifying straight lines and other geometric objects are
scan converted into a set of discrete intensity points.
4
5. Introduction
5
• Filling the polygon means highlighting all pixels which lie inside the polygon with
any color other than background color.
• There are two basic approaches used to fill the polygon.
• Seed Fill
• Scan-line algorithm
6. Polygon Filling
6
Seed Fill
• One way to fill a polygon is to start from a given “seed”, point known to
be inside the polygon and highlight outward from this point i.e.
neighboring pixels until we encounter the boundary pixels.
• This approach is known as seed fill because color flows from the seed pixel
until reaching the polygon boundary, like water flooding on the surface of
the container.
7. Polygon Filling
Scan-line algorithm
• Another approach to fill the polygon is to check whether the pixel is inside the
polygon or outside the polygon and then highlight pixels which lie inside the
polygon.
• This approach is known as scan-line algorithm.
• It avoids the need for a seed pixel but it requires some computation.
7
8. Seed fill algorithm
8
• In this method, we start with a given seed, point known to be inside the polygon
& highlight outward from this point i.e. neighboring pixels until we encounter the
boundary pixels.
• This approach is called seed fill.
• The seed fill algorithm is further classified as
• Boundary fill algorithm
• Flood fill algorithm
9. Seed fill algorithm
9
• Connectivity of graphs
4-connected graph 8-connected graph
• The region can be defined in terms of 4-connected or 8-connected, as shown in the figure.
• For a 4-coonected region every point is spanned by a combination of four moves left, right,
top and bottom respectively.
• For a 8-connected region, the same can be spanned using two horizontal, two vertical, and
four diagonal directions respectively.
10. Boundary fill algorithm
• This method begins with a starting point, called seed, inside the region, filling
that point with the specified fill color.
• Then examine the neighboring pixels to check whether the boundary pixel is
reached.
• If boundary pixels are not reached, pixels are highlighted and the process is
continued until boundary pixels are reached.
• This process involves checking of boundaries.
10
14. Flood-Fill Algorithm
• Sometimes we want to fill in (or recolor) an area that is not defined within a
single color boundary.
• We can paint such areas by replacing a specified interior color instead of
searching for a boundary color value.
• This approach is called a flood-fill algorithm.
14
15. Flood-Fill Algorithm
• We start from a specified interior point (x, y) and reassign all pixel values that are
currently set to a given interior color with the desired fill color.
• If the area we want to paint has more than one interior color, we can first reassign pixel
values so that all interior points have the same color.
• Using either a 4-connected or 8-connected approach, we then step through pixel
positions until all interior points have been repainted.
• The following procedure flood fills a 4-connected region recursively, starting from the
input position.
15
17. ScanLine Polygon Fill Algorithm
15
• For eachscanline crossing a polygon, this algorithm locates the
intersectionpointsof the scanline withthe polygon edges.
• These intersection points are then sorted from left to right and
the corresponding positionsbetween each intersection pair are
set to the specified fill color.
• The four pixel intersection positions with the polygon
boundaries define two stretches of interior pixels from x=10 to
x=14 and fromx=18 to x=24.
• The scan line algorithm first finds the largest and smallest y
valuesof the polygon.
• It then starts with the largest y value & works its down,
scanning fromleft to right.
18. ScanLine Polygon Fill Algorithm
16
• Theimportant task isto find the intersection pointsof the scanlinewith the polygonboundary.
• Whenintersectionpointsare even,theyare sortedfromleft toright, paired andpixelsbetweenpaired pointsare
setto the fill color.
• Whenscan lineintersectpolygonvertex,a specialhandling isrequired to find the exact intersection points.
• T
ohandlesuchcases,lookat theotherendpointof thetwo line segments of the polygon whichmeetat thisvertex.
• If thesepointslie onthesame(up& down)sideof thescan line,thenthispointinquestioncountsasanevennumberof
intersection.
• If they lie onopposite sidesof the scanline, thenthe pointis counted assingle intersection.
19. ScanLinePolygonFill Algorithm
• Each scan line intersects the vertex or
verticesof the polygon.
• For scan line 1,the other end points of the line
segment of the polygonare B& Dwhichlie on
the sameside of the scanline.
• Hence there are two intersections
resulting two pairs:1-2 & 3-4.
• Intersections points are 2 & 3 are actually
samepoints.
17
A C
D
E
F
G
H
J I
B
20. ScanLinePolygonFill Algorithm
18
• Forscanline 2,the other endpoints(D& F)of thetwo line segmentsof thepolygon lie onthe
oppositesides of the scanline.
• Hence,thereisa singleintersectionresultingtwopairs: 1-2 & 3-4.
• F
or scanline 3,two verticesare the intersection points.
• F
or vertex F
, the other end points E& G of the two line segmentsof the polygon lie onthe
sameside of the scanline.
• F
or vertex H, the other end points G & I of the two line segments of the polygon lie on the
opposite side of the scanline.
21. ScanLinePolygonFill Algorithm
• At vertex Fthere are two intersections& at vertex Hthere isonly one intersection.
• Thisresultstwo pairs:1-2 and 3-4 and points 2-3 are actually samepoints
• It isnecessaryto calculate x intersection points for scanline with every polygon side.
• Thesecalculations canbe simplified by using CoherenceProperty.
• A coherence property of a scene isa property of a sceneby which we can relate one part of a scene
withthe other parts of the scene.
• Slope of an edge isused asa coherenceproperty.
• By using this property we can determine the x intersection value on the lower scan line if the x
intersection value for current scan line isknown.
22. ScanLinePolygonFill Algorithm
20
• Thisisgivenas
• xi+1 = xi – 1/m
where misthe slope of the edge.
• As we move from top to bottom value of y coordinates between the two
scanline changesby 1.
• yi+1 = yi -1
• Many times it isnot necessary to compute the x intersection for scan line
with every polygon side.
• We need to consider only the polygon sides with endpoints straddling
the current scanline.
23. ScanLinePolygonFill Algorithm
21
• It will be easier to identify which polygon sides should be tested for x
intersection, if we first sortthesidesin order of theirmaximum y value.
• Oncethesidesare sorted wecanprocessthe scanlinesfrom top of the polygon to
its bottom producing an active edge list for eachscan line crossing the polygon
boundaries.
• Theactive edge list for a scanlinecontain all edgescrossed by that scanline.