Dark Mode
Image

Filled Area Primitives

Region filling is the process of filling image or region. Filling can be of boundary or interior region as shown in fig. Boundary Fill algorithms are used to fill the boundary and flood-fill algorithm are used to fill the interior.

Filled Area Primitives

Boundary Filled Algorithm:

This algorithm uses the recursive method. First of all, a starting pixel called as the seed is considered. The algorithm checks boundary pixel or adjacent pixels are colored or not. If the adjacent pixel is already filled or colored then leave it, otherwise fill it. The filling is done using four connected or eight connected approaches.

Boundary Filled Algorithm

Four connected approaches is more suitable than the eight connected approaches.

Polymorphism in Java | Dynamic Method Dispatch

1. Four connected approaches: In this approach, left, right, above, below pixels are tested.

2. Eight connected approaches: In this approach, left, right, above, below and four diagonals are selected.

Boundary can be checked by seeing pixels from left and right first. Then pixels are checked by seeing pixels from top to bottom. The algorithm takes time and memory because some recursive calls are needed.

Problem with recursive boundary fill algorithm:

It may not fill regions sometimes correctly when some interior pixel is already filled with color. The algorithm will check this boundary pixel for filling and will found already filled so recursive process will terminate. This may vary because of another interior pixel unfilled.

So check all pixels color before applying the algorithm.

Algorithm:

  1. Procedure fill (x, y, color, color1: integer)  
  2. int c;  
  3. c=getpixel (x, y);  
  4. if (c!=color) (c!=color1)  
  5. {  
  6.     setpixel (x, y, color)  
  7.     fill (x+1, y, color, color 1);  
  8.      fill (x-1, y, color, color 1);  
  9.     fill (x, y+1, color, color 1);  
  10.     fill (x, y-1, color, color 1);  
  11. }  

Comment / Reply From