SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Filled Area Primitives
Module 2
Display and Drawing of Graphics Primitives
SPLINE CURVE
 In computer graphics, a spline is a curve that
connects two or more specific points, or
that is defined by two or more points.
Polygon
A Polygon is a plane figure that is bounded by finite
chain of straight line segments to form a closed
chain or loop
There are two types of polygons
1.Convex
2. Concave
 Convex: A convex polygon is a polygon in
which the line segment joining any two points
within the polygon lies completely inside
polygon.
 Concave: A concave polygon is a polygon in
which the line segment joining any two points
within the polygon may not lie completely
inside polygon.
Filled Area Primitives:
 For filling a given picture or object with color’s, we
can do it in two ways in C programming. The two
ways are given below:
 Using filling algorithms such as Floodfill algorithm,
Boundary fill algorithm and scanline polygon fill
algorithm, we can color the objects.
 Using inbuilt graphics functions such as
floodfill(),setfillstyle() we can fill the object with
color’s directly without using any filling algorithm.
 Here we will see the filling algorithms
The Filling Algorithms
Three Algorithms for filling areas:
 1) Boundary Fill Algorithm
 2)Flood fill Algorithm
 3) Scan Line Polygon Fill Algorithm
Boundary Fill Algorithm:
 Start at a point inside a region and paint the
interior outward toward the boundary.
 If the boundary is specified in a single color, the fill
algorithm processed outward pixel by pixel until
the boundary color is encountered.
 A boundary-fill procedure accepts as input the
coordinate of the interior point (x, y), a fill color,
and a boundary color.
Algorithm:
 The following steps illustrate the idea of the
recursive boundary-fill algorithm:
 Start from an interior point.
 If the current pixel is not already filled and if it is
not an edge point, then set the pixel with the fill
color, and store its neighboring pixels (4 or 8-
connected). Store only neighboring pixel that is not
already filled and is not an edge point.
 Select the next pixel from the stack, and continue
with step 2.
 In 4 connected approach, we can fill an object in
only 4 directions. We have 4 possibilities for
proceeding to next pixel from current pixel.
 In 8 connected approach, we can fill an object in 8
directions. We have 8 possibilities for proceeding
to next pixel from current pixel.
 Function for 4 connected approach:
void boundary_fill(int x, int y, int fcolor, int bcolor)
{
if ((getpixel(x, y) != bcolor) && (getpixel(x, y) != fcolor))
{
putpixel(x, y, fcolor);
boundary_fill(x + 1, y, fcolor, bcolor);
boundary_fill(x - 1, y, fcolor, bcolor);
boundary_fill(x, y + 1, fcolor, bcolor);
boundary_fill(x, y - 1, fcolor, bcolor);
}
}
Function for 8 connected approach:
void boundary_fill(int x, int y, int fcolor, int bcolor)
{ if ((getpixel(x, y) != bcolor) && (getpixel(x, y) != fcolor))
{putpixel(x, y, fcolor);
boundary_fill(x + 1, y, fcolor, bcolor);
boundary_fill(x , y+1, fcolor, bcolor);
boundary_fill(x+1, y + 1, fcolor, bcolor);
boundary_fill(x-1, y - 1, fcolor, bcolor);
boundary_fill(x-1, y, fcolor, bcolor);
boundary_fill(x , y-1, fcolor, bcolor);
boundary_fill(x-1, y + 1, fcolor, bcolor);
boundary_fill(x+1, y - 1, fcolor, bcolor);
}
}
Flood Fill Algorithm
 Sometimes we want to fill in (recolor) an area that
is not defined within a single color boundary. We
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.
 We start from a specified interior pixel (x, y) and
reassign all pixel values that are currently set to a
given interior color with the desired fill color.
 If the area has more than one interior color, we can
first reassign pixel values so that all interior pixels
have the same color.
 Using either 4-connected or 8-connected approach,
we then step through pixel positions until all
interior pixels have been repainted
4 connected Flood Fill approach:
 We can implement flood fill algorithm by using
recursion.
 First all the pixels should be reassigned to common
color. here common color is black.
 Start with a point inside given object, check the
following condition: if(getpixel(x,y)==old_col)---
old_col is common color
 If above condition is satisfied, then following 4 steps
are followed in filling the object.
floodfill(x,y,fill_col,old_col)
{
if(getpixel(x,y)==old_col)
{
putpixel(x,y,fill_col);
flood(x+1,y,fill_col,old_col);
flood(x-1,y,fill_col,old_col);
flood(x,y+1,fill_col,old_col);
flood(x,y-1,fill_col,old_col);
}
}
8 connected Flood fill approach:
 We can implement flood fill algorithm by using
recursion.
 First all the pixels should be reassigned to common
color. here common color is black.
 Start with a point inside given object, check the
following condition: if(getpixel(x,y)==old_col)---
old_col is common color
 If above condition is satisfied, then following 8 steps
are followed in filling the object.
floodfill(x,y,fill_col,old_col)
{if(getpixel(x,y)==old_col)
{putpixel(x,y,fill_col);
flood(x+1,y,fill_col,old_col);
flood(x-1,y,fill_col,old_col);
flood(x,y+1,fill_col,old_col);
flood(x,y-1,fill_col,old_col);
flood(x + 1, y - 1, fill_col, old_col);
flood(x + 1, y + 1, fill_col, old_col);
flood(x - 1, y - 1, fill_col, old_col);
flood(x - 1, y + 1, fill_col, old_col);
}
}
Scan Line Polygon Fill Algorithm
This algorithm works by intersecting scanline
with polygon edges and fills the polygon between
pairs of intersections.
Algorithm:
1. We will process the polygon edge after edge, and
store in the edge Table.
2. Storing is done by storing the edge in the same
scanline edge tuple as
the lowermost point's y-coordinate value of the
edge.
 3. After addition of any edge in an edge tuple,
the tuple is sorted using insertion sort,
according to its xofymin value.
 4. After the whole polygon is added to the
edge table, the figure is now filled.
 5. Filling is started from the first scanline at
the bottom, and continued till the top.
 6. Now the active edge table is taken and the
following things are repeated for each
scanline:
 i. Copy all edge buckets of the designated scanline
to the active edge tuple
 ii. Perform an insertion sort according to the xofymin values
 iii. Remove all edge buckets whose ymax is equal
or greater than the scanline
 iv. Fillup pairs of edges in active tuple, if any vertex is got,follow
these instructions:
 o If both lines intersecting at the vertex are on the same side of
the scanline, consider it as two points.
 o If lines intersecting at the vertex are at opposite sides of the
scanline, consider it as only one point.
 v.Update the xofymin by adding slopeinverse for each bucket.
Inside-Outside test
 When filling polygons we should decide
whether a particular point is interior or
exterior to a polygon
 Two approaches:
1. Even-odd Method
2. Winding Number Method
1. Even-odd Method:
Count=even->exterior pixel
Count=odd->interior pixel
Unit-2 PPT.ppt

Weitere ähnliche Inhalte

Ähnlich wie Unit-2 PPT.ppt

B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiB. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiTekendra Nath Yogi
 
#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
 
computer notes - Stack
computer notes - Stackcomputer notes - Stack
computer notes - Stackecomputernotes
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_projectManish Jauhari
 
Area filling algo
Area filling algoArea filling algo
Area filling algoPrince Soni
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
Unit2- line clipping.pptx
Unit2- line clipping.pptxUnit2- line clipping.pptx
Unit2- line clipping.pptxRYZEN14
 
Single Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpSingle Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpMath Homework Solver
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdffaxteldelhi
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesOmprakash Chauhan
 
Computer Graphics Report
Computer Graphics ReportComputer Graphics Report
Computer Graphics ReportKoshy Geoji
 

Ähnlich wie Unit-2 PPT.ppt (20)

Polygon
PolygonPolygon
Polygon
 
CG_U2_M2.pptx
CG_U2_M2.pptxCG_U2_M2.pptx
CG_U2_M2.pptx
 
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath YogiB. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
B. SC CSIT Computer Graphics Unit 1.3 By Tekendra Nath Yogi
 
Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
#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
 
computer notes - Stack
computer notes - Stackcomputer notes - Stack
computer notes - Stack
 
Shi.pdf
Shi.pdfShi.pdf
Shi.pdf
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_project
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
The1
The1The1
The1
 
Unit2- line clipping.pptx
Unit2- line clipping.pptxUnit2- line clipping.pptx
Unit2- line clipping.pptx
 
Single Variable Calculus Assignment Help
Single Variable Calculus Assignment HelpSingle Variable Calculus Assignment Help
Single Variable Calculus Assignment Help
 
Lane Detection
Lane DetectionLane Detection
Lane Detection
 
Please make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdfPlease make the complete program, distinguishing between each class .pdf
Please make the complete program, distinguishing between each class .pdf
 
Polygons - Computer Graphics - Notes
Polygons - Computer Graphics - NotesPolygons - Computer Graphics - Notes
Polygons - Computer Graphics - Notes
 
14485616.ppt
14485616.ppt14485616.ppt
14485616.ppt
 
Unit 4 notes
Unit 4 notesUnit 4 notes
Unit 4 notes
 
Computer Graphics Report
Computer Graphics ReportComputer Graphics Report
Computer Graphics Report
 

Kürzlich hochgeladen

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringJuanCarlosMorales19600
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 

Kürzlich hochgeladen (20)

IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Piping Basic stress analysis by engineering
Piping Basic stress analysis by engineeringPiping Basic stress analysis by engineering
Piping Basic stress analysis by engineering
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

Unit-2 PPT.ppt

  • 1. Filled Area Primitives Module 2 Display and Drawing of Graphics Primitives
  • 2. SPLINE CURVE  In computer graphics, a spline is a curve that connects two or more specific points, or that is defined by two or more points.
  • 3.
  • 4. Polygon A Polygon is a plane figure that is bounded by finite chain of straight line segments to form a closed chain or loop There are two types of polygons 1.Convex 2. Concave
  • 5.  Convex: A convex polygon is a polygon in which the line segment joining any two points within the polygon lies completely inside polygon.  Concave: A concave polygon is a polygon in which the line segment joining any two points within the polygon may not lie completely inside polygon.
  • 6. Filled Area Primitives:  For filling a given picture or object with color’s, we can do it in two ways in C programming. The two ways are given below:  Using filling algorithms such as Floodfill algorithm, Boundary fill algorithm and scanline polygon fill algorithm, we can color the objects.  Using inbuilt graphics functions such as floodfill(),setfillstyle() we can fill the object with color’s directly without using any filling algorithm.  Here we will see the filling algorithms
  • 7. The Filling Algorithms Three Algorithms for filling areas:  1) Boundary Fill Algorithm  2)Flood fill Algorithm  3) Scan Line Polygon Fill Algorithm
  • 8. Boundary Fill Algorithm:  Start at a point inside a region and paint the interior outward toward the boundary.  If the boundary is specified in a single color, the fill algorithm processed outward pixel by pixel until the boundary color is encountered.  A boundary-fill procedure accepts as input the coordinate of the interior point (x, y), a fill color, and a boundary color.
  • 9. Algorithm:  The following steps illustrate the idea of the recursive boundary-fill algorithm:  Start from an interior point.  If the current pixel is not already filled and if it is not an edge point, then set the pixel with the fill color, and store its neighboring pixels (4 or 8- connected). Store only neighboring pixel that is not already filled and is not an edge point.  Select the next pixel from the stack, and continue with step 2.
  • 10.  In 4 connected approach, we can fill an object in only 4 directions. We have 4 possibilities for proceeding to next pixel from current pixel.  In 8 connected approach, we can fill an object in 8 directions. We have 8 possibilities for proceeding to next pixel from current pixel.
  • 11.  Function for 4 connected approach: void boundary_fill(int x, int y, int fcolor, int bcolor) { if ((getpixel(x, y) != bcolor) && (getpixel(x, y) != fcolor)) { putpixel(x, y, fcolor); boundary_fill(x + 1, y, fcolor, bcolor); boundary_fill(x - 1, y, fcolor, bcolor); boundary_fill(x, y + 1, fcolor, bcolor); boundary_fill(x, y - 1, fcolor, bcolor); } }
  • 12. Function for 8 connected approach: void boundary_fill(int x, int y, int fcolor, int bcolor) { if ((getpixel(x, y) != bcolor) && (getpixel(x, y) != fcolor)) {putpixel(x, y, fcolor); boundary_fill(x + 1, y, fcolor, bcolor); boundary_fill(x , y+1, fcolor, bcolor); boundary_fill(x+1, y + 1, fcolor, bcolor); boundary_fill(x-1, y - 1, fcolor, bcolor); boundary_fill(x-1, y, fcolor, bcolor); boundary_fill(x , y-1, fcolor, bcolor); boundary_fill(x-1, y + 1, fcolor, bcolor); boundary_fill(x+1, y - 1, fcolor, bcolor); } }
  • 13. Flood Fill Algorithm  Sometimes we want to fill in (recolor) an area that is not defined within a single color boundary. We 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.  We start from a specified interior pixel (x, y) and reassign all pixel values that are currently set to a given interior color with the desired fill color.
  • 14.  If the area has more than one interior color, we can first reassign pixel values so that all interior pixels have the same color.  Using either 4-connected or 8-connected approach, we then step through pixel positions until all interior pixels have been repainted
  • 15.
  • 16. 4 connected Flood Fill approach:  We can implement flood fill algorithm by using recursion.  First all the pixels should be reassigned to common color. here common color is black.  Start with a point inside given object, check the following condition: if(getpixel(x,y)==old_col)--- old_col is common color  If above condition is satisfied, then following 4 steps are followed in filling the object.
  • 18. 8 connected Flood fill approach:  We can implement flood fill algorithm by using recursion.  First all the pixels should be reassigned to common color. here common color is black.  Start with a point inside given object, check the following condition: if(getpixel(x,y)==old_col)--- old_col is common color  If above condition is satisfied, then following 8 steps are followed in filling the object.
  • 19. floodfill(x,y,fill_col,old_col) {if(getpixel(x,y)==old_col) {putpixel(x,y,fill_col); flood(x+1,y,fill_col,old_col); flood(x-1,y,fill_col,old_col); flood(x,y+1,fill_col,old_col); flood(x,y-1,fill_col,old_col); flood(x + 1, y - 1, fill_col, old_col); flood(x + 1, y + 1, fill_col, old_col); flood(x - 1, y - 1, fill_col, old_col); flood(x - 1, y + 1, fill_col, old_col); } }
  • 20. Scan Line Polygon Fill Algorithm This algorithm works by intersecting scanline with polygon edges and fills the polygon between pairs of intersections. Algorithm: 1. We will process the polygon edge after edge, and store in the edge Table. 2. Storing is done by storing the edge in the same scanline edge tuple as the lowermost point's y-coordinate value of the edge.
  • 21.  3. After addition of any edge in an edge tuple, the tuple is sorted using insertion sort, according to its xofymin value.  4. After the whole polygon is added to the edge table, the figure is now filled.  5. Filling is started from the first scanline at the bottom, and continued till the top.  6. Now the active edge table is taken and the following things are repeated for each scanline:
  • 22.  i. Copy all edge buckets of the designated scanline to the active edge tuple  ii. Perform an insertion sort according to the xofymin values  iii. Remove all edge buckets whose ymax is equal or greater than the scanline  iv. Fillup pairs of edges in active tuple, if any vertex is got,follow these instructions:  o If both lines intersecting at the vertex are on the same side of the scanline, consider it as two points.  o If lines intersecting at the vertex are at opposite sides of the scanline, consider it as only one point.  v.Update the xofymin by adding slopeinverse for each bucket.
  • 23. Inside-Outside test  When filling polygons we should decide whether a particular point is interior or exterior to a polygon  Two approaches: 1. Even-odd Method 2. Winding Number Method 1. Even-odd Method: Count=even->exterior pixel Count=odd->interior pixel