This document discusses techniques for filling 2D shapes and regions in raster graphics. It covers seed fill algorithms that start with an interior seed point and grow outward, filling neighboring pixels. Boundary fill and flood fill are described as variations. The document also discusses raster-based filling that processes shapes one scanline at a time. Methods for filling polygons are presented, including using the even-odd rule or winding number rule to determine if a point is inside the polygon boundary.
Cohen-Sutherland Line Clipping Algorithm:
When drawing a 2D line on screen, it might happen that one or both of the endpoints are outside the screen while a part of the line should still be visible. In that case, an efficient algorithm is needed to find two new endpoints that are on the edges on the screen, so that the part of the line that's visible can now be drawn. This way, all those points of the line outside the screen are clipped away and you don't need to waste any execution time on them.
A good clipping algorithm is the Cohen-Sutherland algorithm for this solution.
By,
Maruf Abdullah Rion
Cohen-Sutherland Line Clipping Algorithm:
When drawing a 2D line on screen, it might happen that one or both of the endpoints are outside the screen while a part of the line should still be visible. In that case, an efficient algorithm is needed to find two new endpoints that are on the edges on the screen, so that the part of the line that's visible can now be drawn. This way, all those points of the line outside the screen are clipped away and you don't need to waste any execution time on them.
A good clipping algorithm is the Cohen-Sutherland algorithm for this solution.
By,
Maruf Abdullah Rion
This slide contain description about the line, circle and ellipse drawing algorithm in computer graphics. It also deals with the filled area primitive.
This slide contain description about the line, circle and ellipse drawing algorithm in computer graphics. It also deals with the filled area primitive.
At the end of this lecture, you should be able to;
describe the importance of morphological features in an image.
describe the operation of erosion, dilation, open and close operations.
identify the practical advantage of the morphological operations.
apply morphological operations for problem solving.
My talk about computational geometry in NTU's APEX Club in NTU, Singapore in 2007. The club is for people who are keen on participating in ACM International Collegiate Programming Contests organized by IBM annually.
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
Notes of 2D Transformation including Translation, Rotation, Scaling, Reflection, Shearing with solved problem.
Clipping algorithm like cohen-sutherland-hodgeman, midpoint-subdivision with solved problem.
By analysing the explanation of the classical heapsort algorithm via the method of levels of abstraction mainly due to Floridi, we give a concrete and precise example of how to deal with algorithmic knowledge. To do so, we introduce a concept already implicit in the method, the ‘gradient of explanations’. Analogously to the gradient of abstractions, a gradient of explanations is a sequence of discrete levels of explanation each one refining the previous, varying formalisation, and thus providing progressive evidence for hidden information. Because of this sequential and coherent uncovering of the information that explains a level of abstraction—the heapsort algorithm in our guiding example—the notion of gradient of explanations allows to precisely classify purposes in writing software according to the informal criterion of ‘depth’, and to give a precise meaning to the notion of ‘concreteness’.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
4. Region filling
The process of “coloring in” a region of an image
Requirements:
1. A digital representation of the shape
a. The shape must be closed.
b. It must have a well defined inside and outside.
2. A test for determining if a point is inside or outside of the shape
3. A rule or procedure for determining the colors of each point
inside the shape
5. Describing a region: Bounding pixels
“Inside” is determined by the boundary and a seed point
All points connected to the seed point are inside
Digital outline and seed points Filled outlines
6. Describing a region: Color range
“Inside” is determined by a color or color range
Original image Pink pixels have been filled yellow
7. Describing a region: Geometrically
“Inside-ness” is determined by evaluating an inequality
Points satisfying the inequality are inside
x2 + y2 < R2
The inside of a
circle of radius R
0 < x < 1
0 < y < 1
The inside of
a unit square
R
x
y
x
y
1
1
8. Describing a region: Geometrically
A set of edge equations and a rule for determining the interior
Inside is determined by testing the rule for each edge
• Example:
• A list of directed edges:
• line from (0,0) to (1, 0)
• line from (1,0) to (1, 1)
• line from (1,1) to (0, 1)
• line from (0, 1) to (0,0)
• Rule for interior points:
• interior points lie to the right
of all of the edges x
y
1
1
4 directed edges
9. Pixel-level vs. geometric descriptions
Pixel-level: Describe a region in terms of
• its bounding pixels (boundary-defined), or
• all of the pixels that comprise it (interior-defined)
Geometric: Define a region by connected lines and curves
10. Approaches to filling regions
Seed Fill Algorithms
• Start will an interior seed
point and grow
• Pixel-based descriptions
Raster-Based Filling
• Fill the interior one raster
scan line at a time
• Geometric descriptions
12. Seed Fill
1. Select a seed point inside a region
2. Move outwards from the seed point
a. If pixel is not set, set pixel
b. Process each neighbor of pixel that is inside the region
1. Select a
seed point
2. Move outwards
to neighbors.
Stop when the
region is filled.
13. Selecting the seed point
Difficult to place the seed point automatically
What is the inside of this shape?
14. Seed Fill algorithm
user selects seedPixel
initialize a fillList to contain seedPixel
while (fillList not empty)
{
pixel next pixel from fillList
setPixel(pixel)
for (each of pixel’s neighbors)
{
if (neighbor is inside region && neighbor not set)
add neighbor to fillList
}
}
16. Determining neighbors
Different fill results for 4-connected and 8-connected regions
Fill using 8-connected neighbors
Fill using 4-connected neighbors
Original boundary
Magnified area
17. Determining “inside-ness” of neighbors
Boundary-defined region
• Use boundary fill
• Set all connected pixels within the boundary
Interior-defined region
• Use flood fill
• Set all connected pixels that have similar color
18. Boundary Fill
1. Region described by a set of bounding pixels
2. A seed pixel is set inside the boundary
Seed
pixel
Bounding
pixel
19. Boundary Fill
1. Region described by a set of bounding pixels
2. A seed pixel is set inside the boundary
3. Check if this pixel is a bounding pixel or has already been filled
4. If no to both, fill it and make neighbors new seeds
20. Boundary Fill
1. Region described by a set of bounding pixels
2. A seed pixel is set inside the boundary
3. Check if this pixel is a bounding pixel or has already been filled
4. If no to both, fill it and make neighbors new seeds
21. Boundary Fill
1. Region described by a set of bounding pixels
2. A seed pixel is set inside the boundary
3. Check if this pixel is a bounding pixel or has already been filled
4. If no to both, fill it and make neighbors new seeds
22. Boundary Fill
1. Region described by a set of bounding pixels
2. A seed pixel is set inside the boundary
3. Check if this pixel is a bounding pixel or has already been filled
4. If no to both, fill it and make neighbors new seeds
Image after 4-connected boundary fill
23. Flood Fill
1. Region is a patch of like-colored pixels
2. A seed pixel is set and a range of colors is defined
Seed
point
24. Flood Fill
1. Region is a patch of like-colored pixels
2. A seed pixel is set and a range of colors is defined
3. Check if the pixel is in the color range
4. If yes, fill it and make the neighbors news seeds
25. Flood Fill
1. Region is a patch of like-colored pixels
2. A seed pixel is set and a range of colors is defined
3. Check if the pixel is in the color range
4. If yes, fill it and make the neighbors news seeds
26. Flood Fill
1. Region is a patch of like-colored pixels
2. A seed pixel is set and a range of colors is defined
3. Check if the pixel is in the color range
4. If yes, fill it and make the neighbors news seeds
27. Image after 4-connected flood fill
Flood Fill
1. Region is a patch of like-colored pixels
2. A seed pixel is set and a range of colors is defined
3. Check if the pixel is in the color range
4. If yes, fill it and make the neighbors news seeds
28. Improving Seed Fill
Shortcomings of boundary fill and flood fill:
• Time
• Large number of recursive calls
• Pixels might be considered more than once (test if set, test if inside)
• Memory
• Don’t know how big the fill list should be
• Could be all of the image pixels
• More if our algorithm allows us to consider a pixel more than once
29. Improving Seed Fill
Goal: Improve performance and reduce memory
Strategy: Exploit coherence
• Structure the order in which neighboring pixels are processed
• Reduces the number of recursive calls
34. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
35. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
36. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
37. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
38. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
39. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
40. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
41. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
42. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
43. Span-Based Seed Fill Algorithm
1. Start from the seed point
2. Fill the entire horizontal span of pixels inside the region
3. Determine spans of pixels in the rows above and below the
current row that are connected to the current span
4. Add the left-most pixel of these spans to the fill list
5. Repeat until the fill list is empty
44. Approaches to filling regions
Seed Fill Algorithms
• Start will an interior seed
point and grow
• Pixel-based descriptions
Raster-Based Filling
• Fill the interior one raster
scan line at a time
• Geometric descriptions
49. Filling general polygons
Simple approach: Boundary fill
1. Use a line drawing algorithm to draw edges of the polygon with a
boundary color
2. Set a seed pixel inside the boundary
50. Filling general polygons
Simple approach: Boundary fill
1. Use a line drawing algorithm to draw edges of the polygon with a
boundary color
2. Set a seed pixel inside the boundary
3. Inside pixels are connected to the seed pixel via other inside pixels
51. Problems with boundary fill
Pixels are drawn on both sides of the line
• The polygon contains pixels outside of the outline
• Polygons with shared edges will have overlapping pixels
Efficiency
• Would be more efficient to combine edge drawing and filling in one step
52. Edge pixels
Adjacent polygons share edges
When rendered, some pixels along the edges are shared
Need to know what color to use for shared edge pixels
53. Edge pixels
If we draw all edge pixels for each polygon…
• Shared pixels will be rendered more than once
• If setPixel() overwrites the current pixel, the last polygons drawn will
look larger
Green triangle written last
54. Edge pixels
If we draw all edge pixels for each polygon…
• Shared pixels will be rendered more than once
• If setPixel() overwrites the current pixel, the last polygons drawn will
look larger
Blue triangle written last
55. Edge pixels
If we draw all edge pixels for each polygon…
• Shared pixels will be rendered more than once
• If setPixel() overwrites the current pixel, the last polygons drawn will
look larger
• If setPixel() blends the background color with the foreground color,
shared edge pixels will have a blended color
Edge color different than either triangle
56. Gaps between adjacent triangles
Edge pixels
If we do not draw the edge pixels…
• Only interior pixels are drawn
• Gaps appear between polygons and the background shows through
57. Edge pixels
Solution: Only draw some of the edges for each polygon
• Follow convention to determine which edge to draw when edge pixels
are shared
• e.g., draw the polygon’s left edges and horizontal bottom edges
58. Polygon
Described geometrically as a list of connected line segments
• These edges must form a closed shape
Could use a seed fill algorithm
• Rasterize the edges to get a bounding pixel description
• Apply boundary fill
Can do better by using information about the edges
59. Raster-Based Filling of polygons
Approach:
Fill polygons in raster-scan order
Fill spans of pixels inside the polygon along each scan line
60. Polygon
A sequence of vertices connected by edges
Assume that vertices have been rasterized
For each point encountered in the scan, determine whether it is
inside the polygon -- a fill rule:
• Even-odd parity rule
• Non-zero winding number rule
61. Even-Odd Parity Rule
Inside-outside test for a point P:
1. Draw line from P to infinity
• Any direction
• Does not go through any vertex
2. Count the number of times the line crosses an edge
• If the number of crossings is odd, P is inside
• If the number of crossings is even, P is outside
P
2 crossings
P is outside
Line from P
to infinity
62. Non-Zero Winding Number Rule
The outline of the shape must be directed
• The line segments must have a consistent direction so that they form a
continuous, closed path
P
63. Non-Zero Winding Number Rule
Inside-outside test:
1. Determine the winding number W of P
a. Initialize W to zero and draw a line from P to infinity
b. If the line crosses an edge directed from bottom to top, W++
c. If the line crosses an edge directed from top to bottom, W--
2. If the W = 0, P is outside
3. Otherwise, P is inside
+1
-1
P
64. Vertices
Check the vertex type
• Line to infinity pierces the edge
• The vertex connects two upwards or
two downwards edges
• Process a single edge crossing
• Line to infinity grazes the edge
• The vertex connects an upwards and
a downwards edge
• Don’t process any edge crossings
P
Piercing
vertex
P
Grazing
vertex
65. Vertices
An alternative is to ensure that the line doesn’t intersect a vertex
Either use a different line if the first line intersects a vertex
• Could be costly if you have to try several lines
Or preprocess edge vertices to ensure that none of them fall on a scan line
• Add a small floating point value to each vertex y-position
P
66. Standard polygons
Do not self intersect and do not contain holes
The even-odd parity rule and the non-zero winding number rule
give the same results for standard polygons
67. General polygons
Can be self intersecting
Can have interior holes
The non-zero winding number rule and the even-odd parity rule can
give different results for general polygons
Even-odd parity Non-zero winding
69. Raster-Based Filling
Fill polygons in raster-scan order
• Fill spans of pixels inside the polygon along each horizontal scan line
• More efficient addressing by accessing spans of pixels
• Only test pixels at the span endpoints
71. Raster-Based Filling
For each scan line
• Determine points where the scan line intersects the polygon
• Set pixels between intersection points (using a fill rule)
• Even-odd parity rule: set pixels between pairs of intersections
• Non-zero winding rule: set pixels according to the winding number
72. Raster-Based Filling:
Using even-odd parity rule
for (each scan line j)
{
find the intersections between j and each edge
sort the intersections by increasing x-value
//Use the even-odd parity rule to set interior points
for (each pair of x-intersections (x1, x2))
{
while (x1 ≤ i < x2)
setPixel(i, j, fillColor)
}
}
73. Raster-Based Filling:
Using even-odd parity rule
for (each scan line j)
{
find the intersections between j and each edge
sort the intersections by increasing x-value
//Use the even-odd parity rule to set interior points
for (each pair of x-intersections (x1, x2))
{
while (x1 ≤ i < x2)
setPixel(i, j, fillColor)
}
}
Recall convention for setting edge pixels
74. Edge pixels
Fill pixels with centers in between pairs of intersections of the scan
line with the polygon edges
Convention: If an intersection point lies at a pixel center
• The pixel is included if it is a leftmost edge
• The pixel is not included if it is a rightmost edge
Do not include pixels
on the right edge
Include pixels on the left edge
Scan line
75. Raster-Based Filling:
Using non-zero winding rule
for (each scan line j)
{
//Determine points where j intersects the edges
//Set pixels according to the winding number
}
76. Summary
Region descriptions
Seed fill algorithms (pixel-based descriptions)
Boundary fill (boundary-based descriptions)
Flood fill (interior-based descriptions)
Handling of shared edges
Raster-based fill (geometric descriptions)
Fill rules
Even-odd parity
Non-zero winding number
Handling of shared vertices
76