Arvin Bera
(Lecturer CST KPC)
 Types of fill Algorithm
 Scan Line Algorithm
 Flood Fill Algorithm
 Boundary fill Algorithm
 4 connected Polygon
 8 Connected Polygon
 Difference between Floodfill and Boundary fill
Algorithm.
Scan Line Algorithm
Flood Fill Algorithm
Boundary Fill Algorithm
 This algorithm works by intersecting scanline with
polygon edges and fills the polygon between pairs
of intersections. The following steps depict how
this algorithm works.
 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,p1p0,p1, p1,p2p1,p2, and p2,p3p2,p3.
 Step 4 − Fill all those pair of coordinates that are
inside polygons and ignore the alternate pairs.
 In this technique 4-connected pixels are used as
shown in the figure. 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.
 Algorithm
 Step 1 − Initialize the value of seed point seedx,seedyseedx,seedy,
fcolor and dcol.
 Step 2 − Define the boundary values of the polygon.
 Step 3 − Check if the current seed point is of default color, then repeat
the steps 4 and 5 till the boundary pixels reached.
 If getpixel(x, y) = dcol then repeat step 4 and 5
 Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
 Step 5 − Recursively follow the procedure with four neighborhood
points.
 FloodFill (seedx – 1, seedy, fcol, dcol)
 FloodFill (seedx + 1, seedy, fcol, dcol)
 FloodFill (seedx, seedy - 1, fcol, dcol)
 FloodFill (seedx – 1, seedy + 1, fcol, dcol)
 Step 6 − Exit
 There is a problem with this technique. Consider the case as
shown below where we tried to fill the entire region. Here, the
image is filled only partially. In such cases, 4-connected
pixels technique cannot be used.
 In this technique 8-connected pixels are used as shown in
the figure. 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 entire area of the current pixel is covered. This process
will continue until we find a boundary with different color.
 Algorithm
 Step 1 − Initialize the value of seed point seedx,seedyseedx,seedy, fcolor and
dcol.
 Step 2 − Define the boundary values of the polygon.
 Step 3 − Check if the current seed point is of default color then repeat the steps 4
and 5 till the boundary pixels reached
 If getpixel(x,y) = dcol then repeat step 4 and 5
 Step 4 − Change the default color with the fill color at the seed
point.setPixel(seedx, seedy, fcol)
 Step 5 − Recursively follow the procedure with four neighbourhood points
 FloodFill (seedx – 1, seedy, fcol, dcol)
 FloodFill (seedx + 1, seedy, fcol, dcol)
 FloodFill (seedx, seedy - 1, fcol, dcol)
 FloodFill (seedx, seedy + 1, fcol, dcol)
 FloodFill (seedx – 1, seedy + 1, fcol, dcol)
 FloodFill (seedx + 1, seedy + 1, fcol, dcol)
 FloodFill (seedx + 1, seedy - 1, fcol, dcol)
 FloodFill (seedx – 1, seedy - 1, fcol, dcol)
 Step 6 − Exit
 https://youtu.be/WmXKII8Dobw
 https://youtu.be/KuthvFzt6p4
 https://youtu.be/y5XX94Ar5NA
 https://youtu.be/U-DxsSjc3KQ
 https://youtu.be/qcTk6hWp6Qc
Thank you

#KPC #CST #Polygon Fill

  • 1.
  • 3.
     Types offill Algorithm  Scan Line Algorithm  Flood Fill Algorithm  Boundary fill Algorithm  4 connected Polygon  8 Connected Polygon  Difference between Floodfill and Boundary fill Algorithm.
  • 4.
    Scan Line Algorithm FloodFill Algorithm Boundary Fill Algorithm
  • 5.
     This algorithmworks by intersecting scanline with polygon edges and fills the polygon between pairs of intersections. The following steps depict how this algorithm works.
  • 6.
     Step 1− Find out the Ymin and Ymax from the given polygon.
  • 7.
     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,p1p0,p1, p1,p2p1,p2, and p2,p3p2,p3.  Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.
  • 11.
     In thistechnique 4-connected pixels are used as shown in the figure. 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.
  • 12.
     Algorithm  Step1 − Initialize the value of seed point seedx,seedyseedx,seedy, fcolor and dcol.  Step 2 − Define the boundary values of the polygon.  Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the boundary pixels reached.  If getpixel(x, y) = dcol then repeat step 4 and 5  Step 4 − Change the default color with the fill color at the seed point. setPixel(seedx, seedy, fcol)  Step 5 − Recursively follow the procedure with four neighborhood points.  FloodFill (seedx – 1, seedy, fcol, dcol)  FloodFill (seedx + 1, seedy, fcol, dcol)  FloodFill (seedx, seedy - 1, fcol, dcol)  FloodFill (seedx – 1, seedy + 1, fcol, dcol)  Step 6 − Exit
  • 13.
     There isa problem with this technique. Consider the case as shown below where we tried to fill the entire region. Here, the image is filled only partially. In such cases, 4-connected pixels technique cannot be used.
  • 14.
     In thistechnique 8-connected pixels are used as shown in the figure. 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 entire area of the current pixel is covered. This process will continue until we find a boundary with different color.
  • 15.
     Algorithm  Step1 − Initialize the value of seed point seedx,seedyseedx,seedy, fcolor and dcol.  Step 2 − Define the boundary values of the polygon.  Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the boundary pixels reached  If getpixel(x,y) = dcol then repeat step 4 and 5  Step 4 − Change the default color with the fill color at the seed point.setPixel(seedx, seedy, fcol)  Step 5 − Recursively follow the procedure with four neighbourhood points  FloodFill (seedx – 1, seedy, fcol, dcol)  FloodFill (seedx + 1, seedy, fcol, dcol)  FloodFill (seedx, seedy - 1, fcol, dcol)  FloodFill (seedx, seedy + 1, fcol, dcol)  FloodFill (seedx – 1, seedy + 1, fcol, dcol)  FloodFill (seedx + 1, seedy + 1, fcol, dcol)  FloodFill (seedx + 1, seedy - 1, fcol, dcol)  FloodFill (seedx – 1, seedy - 1, fcol, dcol)  Step 6 − Exit
  • 17.
     https://youtu.be/WmXKII8Dobw  https://youtu.be/KuthvFzt6p4 https://youtu.be/y5XX94Ar5NA  https://youtu.be/U-DxsSjc3KQ  https://youtu.be/qcTk6hWp6Qc
  • 18.