Boundary Fill Algorithm in C and C++

Here you will learn about boundary fill algorithm in C and C++.

Boundary Fill is another seed fill algorithm in which edges of the polygon are drawn. Then starting with some seed any point inside the polygon we examine the neighboring pixels to check whether the boundary pixel is reached. If boundary pixels are not reached, pixels are highlighted and process is continued until boundary pixels are reached.

Also Read: Flood Fill Algorithm in C and C++

Flood Fill Algorithm in C and C++

4 Connected Region (Image Source)

Following is the algorithm for filling a region in a recursive manner with color specified fill color (f_color) up to a boundary color specified boundary color (b_color)

Algorithm

1. Create a function named as boundaryfill with 4 parameters (x,y,f_color,b_color).

2. Call it recursively until the boundary pixels are reached.

3. Stop.

Program for Boundary Fill Algorithm in C and C++

C Program

C++ Program

Author Bio:

I am Rahul Maheshwari from India currently pursuing engineering degree in Computer Science. I am passionate about programming and loves to code as much as I can and likes to help people to become better in programming.

Connect with him: Facebook | Linkedin

Comment below if you have doubts or found anything incorrect in above boundary fill algorithm in C and C++.

9 thoughts on “Boundary Fill Algorithm in C and C++”

  1. when we change the values of f_color and b_color the program doesnt work the same..so how should we change the color

  2. The program is not working properly for circle with radius more than 45 in Dosbox (Turbo C for windows), in Dev C++ it is working fine for any radius , can somebody tell what changes should be made in turbo c program?

    1. This is an recursive approach. Due to repeated recursion Dosbox runs out of memory & crashes. Use a Stack/Queue to store neighboring pixels to avoid recursion.

    1. This is an recursive approach. Due to repeated recursion Dosbox runs out of memory & crashes. Use a Stack/Queue to store neighboring pixels to avoid recursion.

Leave a Comment

Your email address will not be published. Required fields are marked *