SlideShare a Scribd company logo
Polygon Filling
It is the process of coloring in a fixed area or region. It also means highlighting all
the pixels which is inside the polygon with any color other than background color.
There are two basic approaches used to fill the polygon.
(1) Seed fill
(i) Boundary fill algorithm
(ii) Flood fill algorithm
(1) Scan line
1) Seed fill - It is the way to fill a polygon. it starts from a given “seed “point
known to be inside the polygon & highlight outward from the point in
neighboring pixels , Until we encounter the boundary pixel. The approach is
called “seed fill.”
The seed fill algorithm is further classified :
(i) Boundary fill algorithm
(ii) Flood fill algorithm
Boundary Fill Algorithm : This algorithm picks a point inside an object and starts to
fill until it hits the boundary of the object. The boundary fill algorithm can be
implemented by
i) 4-connected pixels or
ii) 8-connected pixels.
4-Connected Polygon : In this technique 4-connected pixels are used. We are
putting the pixels above, below, to the right, and to the left side of the current pixels
and this process will continue until we find a boundary with different color.
4 connected pixel
(X , Y)
(X-1,Y) (X+1,Y)
(X,Y-1)
(X,Y+1)
Right
Bottom
Top
Left
Algorithm:
Boundary_fill(x, y, f_color, b_color) //here we created a function that is boundary fill
(x,y)are coordinates of seed pixel, f_color is new color of pixel & b_color is boundary color of
pixel.
{
if(getpixel(x,y) != b_color && getpixel(x,y) != f_color) //The header file graphics.h
contains getpixel() function which returns the color of pixel present at location (x,y).
{
putpixel(x,y, f_color) //The header file graphics.h contains putpixel() function which
plots a pixel at location (x, y) of specified color.
Boundary_fill(x+1, y, f_color, b_color) //here we recursively called boundary fill
function Boundary_fill(x,
y+1, f_color, b_color) Boundary_fill(x-1,y, f_color,
b_color) Boundary_fill(x, y-1, f_color, b_color)
} }
There is a problem with 4-connected techniques.
Consider the case here we tried to fill the entire region. but the image is filled only partially. In
such cases, 4-connected pixels technique cannot be used.
8-Connected Polygon : In this technique 8-connected pixels are used .We are putting pixels
above, below, right and left side of the current pixels as we were doing in 4-connected
technique. In addition to this, we are also putting pixels in diagonals so that the entire area of
the current pixel is covered. This process will continue until we find a boundary with different
color.
(X, Y+1)
(X+1, Y)
(X, Y-1)
(X-1, Y)
(X, Y)
Top
Bottom
Left Right
(X-1, Y+1)
(X-1, Y-1) (X+1, Y-1)
(X+1, Y+1)
Algorithm
Boundary_fill(x,y,f_color,b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color)
Boundary_fill(x+1,y,f_color,b_color)
Boundary_fill(x,y,+1f_color,b_color) Boundary_fill(x-
1,y,f_color,b_color) Boundary_fill(x,y-1,f_color,b_color)
Boundary_fill(x+1,y+1,f_color,b_color)
Boundary_fill((x-1,y-1,f_color,b_color)
Boundary_fill(x+1,y-1,f_color,b_color)
Boundary_fill(x-1,y+1,f_color,b_color)
}
}
(X, Y)
(X-1, Y+1) (X, Y+1) (X+1, Y+1)
(X-1, Y) (X+1, Y)
(X-1, Y-1) (X, Y-1) (X+1, Y-1)
Flood Fill Algorithm :Sometimes we come across an object where we want to fill the area
but its boundary has different colors. We can paint such objects with a specified interior color
instead of searching for a particular boundary color as in boundary filling algorithm.
-It replaces the interior color of the object with the fill color. When no more pixels of the
original interior color exist, the algorithm is completed.
-Once again, this algorithm using the Four-connect or Eight-connect method
Algorithm :
Flood_fill (x,y, old_color, new_color) //here we created a function that is flood fill (x,y)are
coordinates of seed pixel, old is old color of pixel & new is new color of pixel.
{
If (getpixel(x,y) = old_color)
{
Putpixel (x,y, new_color)
Flood_fill (x+1,y, old_color, new_color)
Flood_fill (x-1,y, old_color, new_color)
Flood_fill (x,y,+1 old_color, new_color)
Flood_fill (x,y-1, old_color, new_color)
Flood_fill (x+1,y+1, old_color, new_color)
Flood_fill (x-1,y-1, old_color, new_color)
Flood_fill (x+1,y-1, old_color, new_color)
Flood_fill (x-1,y+1, old_color, new_color)
}
}
(X, Y)
(X-1, Y+1) (X, Y+1) (X+1, Y+1)
(X-1, Y) (X+1, Y)
(X-1, Y-1) (X, Y-1) (X+1, Y-1)
Scan Line Algorithm : Boundary filling requires a lot of processing and in this way
encounters few problems in real time. so alternative is scanline filling as it is very robust in
nature. This algorithm works by intersecting the scanline with polygon edges and fills the
polygon between pairs of intersections.
Scanline filling is filling of polygons using horizontal lines or scanlines. The purpose of this
algorithm is to fill the interior pixels of a polygon.To understand Scanline, think of the image
being drawn by a single pen starting from bottom left, continuing to the right, plotting only
points where there is a point present in the image, and when the line is complete, start from the
next line and continue.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2,
p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e.
p0,p1,p1,p2, and p2,p3
Step 4 − Fill all those pairs of coordinates that are inside polygons and ignore the alternate pairs.
Thank you!!

More Related Content

Similar to CG_U2_M2.pptx

backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
Digtial Image Processing Q@A
Digtial Image Processing Q@ADigtial Image Processing Q@A
Digtial Image Processing Q@A
Chung Hua Universit
 
Online Signal Processing Assignment Help
Online Signal Processing Assignment HelpOnline Signal Processing Assignment Help
Online Signal Processing Assignment Help
Matlab Assignment Experts
 
Wiki Powerpoint
Wiki PowerpointWiki Powerpoint
Wiki Powerpoint
mdrieseberg
 
Wiki Powerpoint
Wiki PowerpointWiki Powerpoint
Wiki Powerpoint
mdrieseberg
 

Similar to CG_U2_M2.pptx (7)

backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
 
Digtial Image Processing Q@A
Digtial Image Processing Q@ADigtial Image Processing Q@A
Digtial Image Processing Q@A
 
Online Signal Processing Assignment Help
Online Signal Processing Assignment HelpOnline Signal Processing Assignment Help
Online Signal Processing Assignment Help
 
Mathematical tools in dip
Mathematical tools in dipMathematical tools in dip
Mathematical tools in dip
 
Wiki Powerpoint
Wiki PowerpointWiki Powerpoint
Wiki Powerpoint
 
Wiki Powerpoint
Wiki PowerpointWiki Powerpoint
Wiki Powerpoint
 
Wiki Powerpoint
Wiki PowerpointWiki Powerpoint
Wiki Powerpoint
 

More from ssuser255bf1

Characteristics of Display Adapter
Characteristics of Display AdapterCharacteristics of Display Adapter
Characteristics of Display Adapter
ssuser255bf1
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
ssuser255bf1
 
1.2.3.pptx
1.2.3.pptx1.2.3.pptx
1.2.3.pptx
ssuser255bf1
 
1.1.2.pdf
1.1.2.pdf1.1.2.pdf
1.1.2.pdf
ssuser255bf1
 
1.1.1.pptx
1.1.1.pptx1.1.1.pptx
1.1.1.pptx
ssuser255bf1
 
CG_U4_M1.pptx
CG_U4_M1.pptxCG_U4_M1.pptx
CG_U4_M1.pptx
ssuser255bf1
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
ssuser255bf1
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
ssuser255bf1
 
CG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptxCG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptx
ssuser255bf1
 

More from ssuser255bf1 (9)

Characteristics of Display Adapter
Characteristics of Display AdapterCharacteristics of Display Adapter
Characteristics of Display Adapter
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
1.2.3.pptx
1.2.3.pptx1.2.3.pptx
1.2.3.pptx
 
1.1.2.pdf
1.1.2.pdf1.1.2.pdf
1.1.2.pdf
 
1.1.1.pptx
1.1.1.pptx1.1.1.pptx
1.1.1.pptx
 
CG_U4_M1.pptx
CG_U4_M1.pptxCG_U4_M1.pptx
CG_U4_M1.pptx
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
CG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptxCG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptx
 

Recently uploaded

6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
top1002
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 

Recently uploaded (20)

6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Basic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparelBasic Industrial Engineering terms for apparel
Basic Industrial Engineering terms for apparel
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 

CG_U2_M2.pptx

  • 1. Polygon Filling It is the process of coloring in a fixed area or region. It also means highlighting all the pixels which is inside the polygon with any color other than background color. There are two basic approaches used to fill the polygon. (1) Seed fill (i) Boundary fill algorithm (ii) Flood fill algorithm (1) Scan line
  • 2. 1) Seed fill - It is the way to fill a polygon. it starts from a given “seed “point known to be inside the polygon & highlight outward from the point in neighboring pixels , Until we encounter the boundary pixel. The approach is called “seed fill.” The seed fill algorithm is further classified : (i) Boundary fill algorithm (ii) Flood fill algorithm
  • 3. Boundary Fill Algorithm : This algorithm picks a point inside an object and starts to fill until it hits the boundary of the object. The boundary fill algorithm can be implemented by i) 4-connected pixels or ii) 8-connected pixels. 4-Connected Polygon : In this technique 4-connected pixels are used. We are putting the pixels above, below, to the right, and to the left side of the current pixels and this process will continue until we find a boundary with different color.
  • 4. 4 connected pixel (X , Y) (X-1,Y) (X+1,Y) (X,Y-1) (X,Y+1) Right Bottom Top Left
  • 5. Algorithm: Boundary_fill(x, y, f_color, b_color) //here we created a function that is boundary fill (x,y)are coordinates of seed pixel, f_color is new color of pixel & b_color is boundary color of pixel. { if(getpixel(x,y) != b_color && getpixel(x,y) != f_color) //The header file graphics.h contains getpixel() function which returns the color of pixel present at location (x,y). { putpixel(x,y, f_color) //The header file graphics.h contains putpixel() function which plots a pixel at location (x, y) of specified color. Boundary_fill(x+1, y, f_color, b_color) //here we recursively called boundary fill function Boundary_fill(x, y+1, f_color, b_color) Boundary_fill(x-1,y, f_color, b_color) Boundary_fill(x, y-1, f_color, b_color) } }
  • 6. There is a problem with 4-connected techniques. Consider the case here we tried to fill the entire region. but the image is filled only partially. In such cases, 4-connected pixels technique cannot be used.
  • 7. 8-Connected Polygon : In this technique 8-connected pixels are used .We are putting pixels above, below, right and left side of the current pixels as we were doing in 4-connected technique. In addition to this, we are also putting pixels in diagonals so that the entire area of the current pixel is covered. This process will continue until we find a boundary with different color. (X, Y+1) (X+1, Y) (X, Y-1) (X-1, Y) (X, Y) Top Bottom Left Right (X-1, Y+1) (X-1, Y-1) (X+1, Y-1) (X+1, Y+1)
  • 8. Algorithm Boundary_fill(x,y,f_color,b_color) { if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color) { putpixel(x,y,f_color) Boundary_fill(x+1,y,f_color,b_color) Boundary_fill(x,y,+1f_color,b_color) Boundary_fill(x- 1,y,f_color,b_color) Boundary_fill(x,y-1,f_color,b_color) Boundary_fill(x+1,y+1,f_color,b_color) Boundary_fill((x-1,y-1,f_color,b_color) Boundary_fill(x+1,y-1,f_color,b_color) Boundary_fill(x-1,y+1,f_color,b_color) } } (X, Y) (X-1, Y+1) (X, Y+1) (X+1, Y+1) (X-1, Y) (X+1, Y) (X-1, Y-1) (X, Y-1) (X+1, Y-1)
  • 9. Flood Fill Algorithm :Sometimes we come across an object where we want to fill the area but its boundary has different colors. We can paint such objects with a specified interior color instead of searching for a particular boundary color as in boundary filling algorithm. -It replaces the interior color of the object with the fill color. When no more pixels of the original interior color exist, the algorithm is completed. -Once again, this algorithm using the Four-connect or Eight-connect method
  • 10. Algorithm : Flood_fill (x,y, old_color, new_color) //here we created a function that is flood fill (x,y)are coordinates of seed pixel, old is old color of pixel & new is new color of pixel. { If (getpixel(x,y) = old_color) { Putpixel (x,y, new_color) Flood_fill (x+1,y, old_color, new_color) Flood_fill (x-1,y, old_color, new_color) Flood_fill (x,y,+1 old_color, new_color) Flood_fill (x,y-1, old_color, new_color) Flood_fill (x+1,y+1, old_color, new_color) Flood_fill (x-1,y-1, old_color, new_color) Flood_fill (x+1,y-1, old_color, new_color) Flood_fill (x-1,y+1, old_color, new_color) } } (X, Y) (X-1, Y+1) (X, Y+1) (X+1, Y+1) (X-1, Y) (X+1, Y) (X-1, Y-1) (X, Y-1) (X+1, Y-1)
  • 11. Scan Line Algorithm : Boundary filling requires a lot of processing and in this way encounters few problems in real time. so alternative is scanline filling as it is very robust in nature. This algorithm works by intersecting the scanline with polygon edges and fills the polygon between pairs of intersections. Scanline filling is filling of polygons using horizontal lines or scanlines. The purpose of this algorithm is to fill the interior pixels of a polygon.To understand Scanline, think of the image being drawn by a single pen starting from bottom left, continuing to the right, plotting only points where there is a point present in the image, and when the line is complete, start from the next line and continue.
  • 12. Step 1 − Find out the Ymin and Ymax from the given polygon. Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3. Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0,p1,p1,p2, and p2,p3 Step 4 − Fill all those pairs of coordinates that are inside polygons and ignore the alternate pairs.