Open In App

Filled Area Primitives Computer Graphics

Last Updated : 14 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Filled Area primitives are used to filling solid colors to an area or image or polygon. Filling the polygon means highlighting its pixel with different solid colors. Following are two filled area primitives:

  1. Seed Fill Algorithm
  2. Scan Fill Algorithm

Seed Fill Algorithm:

In this seed fill algorithm, we select a starting point called seed inside the boundary of the polygon. The seed algorithm can be further classified into two algorithms: Flood Fill and Boundary filled.

Flood Fill Algorithm:

In this flood-fill algorithm, a seed point is taken inside the polygon. The flood fill algorithm is used when the polygon has multiple color boundaries. In this method, the related pixels are replaced with the selected color using fill color. The selected pixel values before are reassigned with the selected color value. This can be done using two approaches either 4-connected or 8-connected.

Flood Fill Algorithm

 

Algorithm:

Function floodfill(x, y, fillcolor, previouscolor)
if (getpixel (x, y) = previouscolor)
{
     setpixel (x, y, fillcolor);
    floodfill( x+1, y, fillcolor,previouscolor);
    floodfill( x-1, y, fillcolor,previouscolor);
    floodfill( x, y+1, fillcolor,previouscolor);
    floodfill( x, y-1, fillcolor,previouscolor);
}
getpixel() - The color of specified pixel.
setpixel() - Sets the pixel to specified color.

Advantages:

  • This method is easy to fill colors in computer graphics.
  • It fills the same color inside the boundary.

Disadvantages:

  • Fails with large area polygons.
  • It is a slow method to fill the area.

Boundary Fill Algorithm:

The boundary fill algorithm uses polygon boundaries. It is also called an edge fill algorithm. In this method, a seed point is taken in the polygon boundary and checks whether the adjacent or neighboring pixel is colored or not. If the adjacent pixel is not colored then, fill it. This can be done using two approaches: 4-connected or 8-connected.

Boundary Fill Algorithm

 

Algorithm:

Function boundaryfill(x, y, color, color1)
int c;
c = getpixel(x ,y);
if (c! =color) & (c!=color1)
{
    setpixel (x, y, color);
   boundaryfill( x+1, y, color, color1);
   boundaryfill( x-1, y, color, color1);
   boundaryfill( x, y+1, color, color1);
   boundaryfill( x, y-1, color, color1);
} 

Advantages:

  • The boundary fill algorithm is used to create attractive paintings.

Disadvantages:

  • In the 4-connected approach, it does not color corners.

Scan Fill Algorithm:

Scan fill algorithm is an area-filling algorithm that fill colors by scanning horizontal lines. These horizontal lines intersect the boundaries of the polygon and fill colors between the intersection points. Its main purpose is to fill colors in the interior pixels of the polygon.

Scan Line Algorithm

Advantages:

  • Scan fill algorithm fills the polygon in the same order as rendering.
  • It takes advantage of coherence thus, a fast algorithm.

Disadvantages:

  • The intensity of the pixels is unequal.
  • Staircase-like appearance when scan line converted to circles.

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads