Flood Fill & Pattern Fil - Lect - 10

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

CSL782/583

Flood Fill
Introduction

•Flood fill is another technique to fill an object. It Is design to resolve the problem of seek fill.
•This technique utilize when we have to fill an object without change the colour of it’s boundary.
•Sometimes it is required to fill in an area that is not defined within a single color boundary.
•In such cases we can fill areas by replacing a specified interior color instead of searching for a
boundary color.
•In such cases we can fill areas by replacing a specified interior color instead of searching for a
boundary color.
Flood Fill Mechanism

•However, here pixels are checked for a specified interior color instead of boundary color and they are
replaced by new color.
•Using either a 4-connected or 8-connected approach, we can step through pixel positions until all
interior point have been filled.
•The procedure illustrates the recursive method for filling 4-connected region using flood-fill algorithm.

•It can also Design using two approach –


1. Flood Fill Four Connected
2. Flood Fill Eight Connected
1. Flood Fill Four Connected

flood-fill4(x, y, new-color, old-color)


{
if(getpixel (x,y) = = old-color)
{
putpixel (x, y, new-color)
flood-fill4 (x + 1, y, new-color, old -color);
flood-fill4 (x, y + 1, new -color, old -color);
flood-fill4 (x - 1, y, new -color, old -color);
flood-fill4 (x, y - l, new -color, old-color);
}
}
Note: 'getpixel' function gives the color of .specified pixel and 'putpixel' function draws the pixel
with specified color.
2. Flood Fill Eight Connected
flood-fill4(x, y, new-color, old-color)
{
if(getpixel (x,y) = = old-color)
{
putpixel (x, y, new-color)
flood-fill4 (x + 1, y, new-color, old -color);
flood-fill4 (x + 1, y+1, new-color, old -color);
flood-fill4 (x, y + 1, new -color, old -color);
flood-fill4 (x-1, y + 1, new -color, old -color);
flood-fill4 (x - 1, y, new -color, old -color);
flood-fill4 (x - 1, y-1, new -color, old -color);
flood-fill4 (x, y - l, new -color, old-color);
flood-fill4 (x+1, y - l, new -color, old-color);
}
}
Pattern Fill

We select the pattern with


setInteriorStyleIndex (pi)
1. Where pattern index parameter pi specifies position in pattern table entry.
2. For example, the following set of statements would fill the area defined in the fillArea
command with the second pattern type stored in the pattern table:
SetInteriorStyle( pattern ) ;
setInteriorStyleIndex ( 2 ) ;
fillArea (n, points);
3. Other function used for setting other style as follows
setpatternsize (dx, dy) setPaternReferencePoint (positicn);

You might also like