SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Dernier

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 

Dernier (20)

Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 

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