This algorithm picks a seed point inside an object and starts to fill until it encounters the boundary of the object. The color of the boundary and the color that we fill should be different for this algorithm to work.
In this algorithm, we assume that color of the boundary is same for the entire object. The boundary fill algorithm can be implemented by 4-connected pixels or 8-connected pixels.
4 Connected Approach:
In 4-connected technique pixels are used as shown in the figure above. We put 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.
8 Connected Approach:
In 8-connected technique pixels are used as shown in the figure above. We put 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.
Code:
If you can't see the code, then Enable JavaScript in you browser
Output:
Note: Just copy the files "CGA.bgi" &" EGAVGA.bgi" from bgi folder to bin. So, if you have copied these 2 files then you can skip writing "C:\\tc\\bgi" in initgraph with just ""(2 double quotes)
Comments
Post a Comment