SlideShare a Scribd company logo
1 of 81
Download to read offline
COMP175: Computer Graphics
Lecture 4
Rasterization:
Region Filling
Drawing 2D shapes
Rasterization of graphics primitives
Midpoint algorithms: useful for drawing outlines
Line segments Circles More general curves
Filling 2D shapes
Solid fill Pattern fill Texture fill
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
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
Describing a region: Color range
“Inside” is determined by a color or color range
Original image Pink pixels have been filled yellow
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
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
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
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
Seed Fill Algorithms
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.
Selecting the seed point
Difficult to place the seed point automatically
What is the inside of this shape?
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
}
}
Determining neighbors
4-connected region
8-connected region
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
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
Boundary Fill
1.  Region described by a set of bounding pixels
2.  A seed pixel is set inside the boundary
Seed
pixel
Bounding
pixel
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
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
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
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
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
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
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
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
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
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
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
Neighbor coherence
Neighboring pixels tend to be in the same region
Span coherence
Neighboring pixels on a scan line tend to be in the same region.
Scan line coherence
The filling patterns of adjacent scan lines tends to be similar.
Span-Based Seed Fill Algorithm
1.  Start from the seed point
Seed point
Span-Based Seed Fill Algorithm
1.  Start from the seed point
2.  Fill the entire horizontal span of pixels inside the region
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
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
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
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
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
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
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
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
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
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
Raster-Based Filling
Axis-aligned rectangle
Defined by its corner points
(xmin, ymin)‫‏‬
(xmax, ymax)‫‏‬
Axis-aligned rectangle
Filled in a straightforward manner
(xmin, ymin)‫‏‬
(xmax, ymax)‫‏‬
for (j = ymin; j < ymax; j++) {
for (i = xmin; i < xmax; i++) {
setPixel(i, j, fillColor)
}
}
Polygon
Described geometrically as a list of connected line segments
•  These edges must form a closed shape
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
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
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
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
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
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
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
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
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
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
Raster-Based Filling of polygons
Approach:
Fill polygons in raster-scan order
Fill spans of pixels inside the polygon along each scan line
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
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
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
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
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
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
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
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
Even-Odd Parity Non-Zero Winding
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
Raster-Based Filling
For each scan line
•  Determine points where the scan line intersects the polygon
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
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)
}
}
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
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
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
}
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
Next time
Efficient raster-based fill algorithms
x-intersection array
Edge lists
Pineda’s algorithm
77
Related ideas
Color replacement
78
Source: digiretus.com Photoshop tutorials
Related ideas
Color replacement
79
Source: gimp.org tutorials
Related ideas
Colorization of black-and-white stills and videos
80
Source: Levin et al. “Colorization Using
Optimization.” SIGGRAPH 04.
Related ideas
Inpainting
81
Source: Criminisi et al. “Region Filling and
Object Removal by Exemplar-Based Image
Inpainting”, IEEE Trans. on Image Proc. 2004.

More Related Content

What's hot

Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output PrimitivesRenita Santhmayora
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniquesMani Kanth
 
raster and random scan
raster and random scanraster and random scan
raster and random scanSonia Pahuja
 
Area filling algo
Area filling algoArea filling algo
Area filling algoPrince Soni
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesOmprakash Chauhan
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
1. Introduction of Computer Graphics
1. Introduction of Computer Graphics1. Introduction of Computer Graphics
1. Introduction of Computer GraphicsAparna Joshi
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmArvind Kumar
 
Character generation
Character generationCharacter generation
Character generationAnkit Garg
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformationSelvakumar Gna
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysSaravana Priya
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)shalinikarunakaran1
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 

What's hot (20)

Attributes of Output Primitives
Attributes of Output PrimitivesAttributes of Output Primitives
Attributes of Output Primitives
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
raster and random scan
raster and random scanraster and random scan
raster and random scan
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Color Models
Color ModelsColor Models
Color Models
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Clipping
ClippingClipping
Clipping
 
1. Introduction of Computer Graphics
1. Introduction of Computer Graphics1. Introduction of Computer Graphics
1. Introduction of Computer Graphics
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
Character generation
Character generationCharacter generation
Character generation
 
Computer graphics basic transformation
Computer graphics basic transformationComputer graphics basic transformation
Computer graphics basic transformation
 
Raster Scan and Raster Scan Displays
Raster Scan and Raster Scan DisplaysRaster Scan and Raster Scan Displays
Raster Scan and Raster Scan Displays
 
Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)Attributes of output primitive(line attributes)
Attributes of output primitive(line attributes)
 
Raster Scan display
Raster Scan displayRaster Scan display
Raster Scan display
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
 

Viewers also liked

Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithmsavelraj
 
Boundary Extraction
Boundary ExtractionBoundary Extraction
Boundary ExtractionMaria Akther
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processingRaghu Kumar
 
10CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 910CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 9Vanishree Arun
 
COM2304: Morphological Image Processing
COM2304: Morphological Image ProcessingCOM2304: Morphological Image Processing
COM2304: Morphological Image ProcessingHemantha Kulathilake
 
A Tutorial on Computational Geometry
A Tutorial on Computational GeometryA Tutorial on Computational Geometry
A Tutorial on Computational GeometryMinh-Tri Pham
 
Clipping Algorithm In Computer Graphics
Clipping Algorithm In Computer GraphicsClipping Algorithm In Computer Graphics
Clipping Algorithm In Computer Graphicsstudent(MCA)
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)Amit Kapoor
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
 
KOISTUDY 지역본선 2차모의고사 풀이집
KOISTUDY 지역본선 2차모의고사 풀이집KOISTUDY 지역본선 2차모의고사 풀이집
KOISTUDY 지역본선 2차모의고사 풀이집ho94949
 
Julieta Sieyra - CV Especialidades
Julieta Sieyra - CV EspecialidadesJulieta Sieyra - CV Especialidades
Julieta Sieyra - CV EspecialidadesJulieta Sieyra
 
Algorithms and Their Explanations
Algorithms and Their ExplanationsAlgorithms and Their Explanations
Algorithms and Their ExplanationsMarco Benini
 
Frequent english words
Frequent english wordsFrequent english words
Frequent english wordsPrince Soni
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingPrince Soni
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5Vanishree Arun
 

Viewers also liked (20)

Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Boundary Extraction
Boundary ExtractionBoundary Extraction
Boundary Extraction
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Morphological image processing
Morphological image processingMorphological image processing
Morphological image processing
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
10CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 910CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 9
 
COM2304: Morphological Image Processing
COM2304: Morphological Image ProcessingCOM2304: Morphological Image Processing
COM2304: Morphological Image Processing
 
A Tutorial on Computational Geometry
A Tutorial on Computational GeometryA Tutorial on Computational Geometry
A Tutorial on Computational Geometry
 
Clipping Algorithm In Computer Graphics
Clipping Algorithm In Computer GraphicsClipping Algorithm In Computer Graphics
Clipping Algorithm In Computer Graphics
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphics
 
Ee 583 lecture10
Ee 583 lecture10Ee 583 lecture10
Ee 583 lecture10
 
KOISTUDY 지역본선 2차모의고사 풀이집
KOISTUDY 지역본선 2차모의고사 풀이집KOISTUDY 지역본선 2차모의고사 풀이집
KOISTUDY 지역본선 2차모의고사 풀이집
 
Julieta Sieyra - CV Especialidades
Julieta Sieyra - CV EspecialidadesJulieta Sieyra - CV Especialidades
Julieta Sieyra - CV Especialidades
 
Engineering Math
Engineering MathEngineering Math
Engineering Math
 
Algorithms and Their Explanations
Algorithms and Their ExplanationsAlgorithms and Their Explanations
Algorithms and Their Explanations
 
Frequent english words
Frequent english wordsFrequent english words
Frequent english words
 
Compututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And RenderingCompututer Graphics - Color Modeling And Rendering
Compututer Graphics - Color Modeling And Rendering
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
 

Similar to COMP175 Rasterization Lecture

ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSnehrurevathy
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptxGavy11
 
Exploring Concepts of Perimeter and Area.pptx
Exploring Concepts of Perimeter and Area.pptxExploring Concepts of Perimeter and Area.pptx
Exploring Concepts of Perimeter and Area.pptxMyrrhBalanayFlorida
 
CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxlara333479
 
#KPC #CST #Polygon Fill
#KPC #CST  #Polygon Fill #KPC #CST  #Polygon Fill
#KPC #CST #Polygon Fill KEIKolkata
 
#KPC #CST #Polygon fill
#KPC #CST #Polygon fill #KPC #CST #Polygon fill
#KPC #CST #Polygon fill KEIKolkata
 

Similar to COMP175 Rasterization Lecture (7)

ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICSATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
ATTRIBUTES OF OUTPUT PRIMITIVES IN COMPUTER GRAPHICS
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Exploring Concepts of Perimeter and Area.pptx
Exploring Concepts of Perimeter and Area.pptxExploring Concepts of Perimeter and Area.pptx
Exploring Concepts of Perimeter and Area.pptx
 
Unit-2 PPT.ppt
Unit-2 PPT.pptUnit-2 PPT.ppt
Unit-2 PPT.ppt
 
CS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptxCS401_M2_L6_Solid Area Scan Conversion.pptx
CS401_M2_L6_Solid Area Scan Conversion.pptx
 
#KPC #CST #Polygon Fill
#KPC #CST  #Polygon Fill #KPC #CST  #Polygon Fill
#KPC #CST #Polygon Fill
 
#KPC #CST #Polygon fill
#KPC #CST #Polygon fill #KPC #CST #Polygon fill
#KPC #CST #Polygon fill
 

More from Kumar

Graphics devices
Graphics devicesGraphics devices
Graphics devicesKumar
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xsltKumar
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xmlKumar
 
Xml basics
Xml basicsXml basics
Xml basicsKumar
 
XML Schema
XML SchemaXML Schema
XML SchemaKumar
 
Publishing xml
Publishing xmlPublishing xml
Publishing xmlKumar
 
Applying xml
Applying xmlApplying xml
Applying xmlKumar
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLKumar
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee applicationKumar
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLKumar
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB FundmentalsKumar
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programmingKumar
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversKumar
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EEKumar
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)Kumar
 
Android structure
Android structureAndroid structure
Android structureKumar
 

More from Kumar (20)

Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
DTD
DTDDTD
DTD
 
Applying xml
Applying xmlApplying xml
Applying xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
How to deploy a j2ee application
How to deploy a j2ee applicationHow to deploy a j2ee application
How to deploy a j2ee application
 
JNDI, JMS, JPA, XML
JNDI, JMS, JPA, XMLJNDI, JMS, JPA, XML
JNDI, JMS, JPA, XML
 
EJB Fundmentals
EJB FundmentalsEJB Fundmentals
EJB Fundmentals
 
JSP and struts programming
JSP and struts programmingJSP and struts programming
JSP and struts programming
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Introduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC DriversIntroduction to JDBC and JDBC Drivers
Introduction to JDBC and JDBC Drivers
 
Introduction to J2EE
Introduction to J2EEIntroduction to J2EE
Introduction to J2EE
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)
 
Android structure
Android structureAndroid structure
Android structure
 

Recently uploaded

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Recently uploaded (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 

COMP175 Rasterization Lecture

  • 1. COMP175: Computer Graphics Lecture 4 Rasterization: Region Filling
  • 2. Drawing 2D shapes Rasterization of graphics primitives Midpoint algorithms: useful for drawing outlines Line segments Circles More general curves
  • 3. Filling 2D shapes Solid fill Pattern fill Texture fill
  • 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
  • 30. Neighbor coherence Neighboring pixels tend to be in the same region
  • 31. Span coherence Neighboring pixels on a scan line tend to be in the same region.
  • 32. Scan line coherence The filling patterns of adjacent scan lines tends to be similar.
  • 33. Span-Based Seed Fill Algorithm 1.  Start from the seed point Seed point
  • 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
  • 46. Axis-aligned rectangle Defined by its corner points (xmin, ymin)‫‏‬ (xmax, ymax)‫‏‬
  • 47. Axis-aligned rectangle Filled in a straightforward manner (xmin, ymin)‫‏‬ (xmax, ymax)‫‏‬ for (j = ymin; j < ymax; j++) { for (i = xmin; i < xmax; i++) { setPixel(i, j, fillColor) } }
  • 48. Polygon Described geometrically as a list of connected line segments •  These edges must form a closed shape
  • 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
  • 70. Raster-Based Filling For each scan line •  Determine points where the scan line intersects the polygon
  • 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
  • 77. Next time Efficient raster-based fill algorithms x-intersection array Edge lists Pineda’s algorithm 77
  • 78. Related ideas Color replacement 78 Source: digiretus.com Photoshop tutorials
  • 80. Related ideas Colorization of black-and-white stills and videos 80 Source: Levin et al. “Colorization Using Optimization.” SIGGRAPH 04.
  • 81. Related ideas Inpainting 81 Source: Criminisi et al. “Region Filling and Object Removal by Exemplar-Based Image Inpainting”, IEEE Trans. on Image Proc. 2004.