SlideShare una empresa de Scribd logo
1 de 13
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!!

Más contenido relacionado

Similar a 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
 

Más de ssuser255bf1

Characteristics of Display Adapter
Characteristics of Display AdapterCharacteristics of Display Adapter
Characteristics of Display Adapterssuser255bf1
 
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.pptxssuser255bf1
 
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.pptxssuser255bf1
 
CG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptxCG_U1_M1_PPT_1.pptx
CG_U1_M1_PPT_1.pptxssuser255bf1
 

Más de 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
 

Último

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
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
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Último (20)

UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
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...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
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, ...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
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
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

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.