Filled Area Primitives Computer Graphics

Filled Area Primitives: Area filling is a method or process that helps us to fill an object, area, or image. We can easily fill the polygon. The polygon filling is defined as filling or highlighting all the pixels. The pixels appear inside the polygon shape with any color other than the background color.

There are two algorithms or methods used to fill the polygon.

  • Seed Fill Algorithm
  • Scan Line Algorithm

Seed Fill Algorithm

In this method, we will select a seed or starting point inside the boundary. We can further divide the seed fill into two parts.

Filled Area Primitives
  1. Flood-fill Algorithm
  2. Boundary-fill Algorithm

Flood-fill Algorithm   

Flood-fill algorithm helps to define a region in the boundary, attached to a point in the multi-dimensional array. It is similar to the bucket tool used in the paint program. The stack-based recursive function is used to implement the algorithm. In flood -fill algorithm, we replace all the associated pixels of the selected color with a fill color. We also check the pixels for a particular interior color, not for boundary color.

Filled Area Primitives

Algorithm of Flood-fill

Procedure flood_fill (p, q, fill_color, Old_color: Integer)

Var

      Current: Integer

      Current = getpixel (p, q)

 If

        (Current = Old_color)

Then

       Start

setpixel (p, q, fill_color);

          flood_fill (p, q+1, fill_color, Old_color);

          flood_fill (p, q-1, fill_color, Old_color);

          flood_fill (p+1, q, fill_color, Old_color);

          flood_fill (p-1, q, fill_color, Old_color);

     End;

Note- Getpixel () defines the color of specified pixel.

          Setpixel () set the pixel with the specified color.

Filled Area Primitives

Advantages of Flood-fill algorithm

  • It provides an easy way to fill color in graphics.
  • The Flood-fill algorithm colors the whole area through interconnected pixels by a single color.
  • The algorithm fills the same color inside the boundary.

Disadvantages of Flood-fill Algorithm

  • It is a more time-consuming algorithm.
  • Sometimes it does not work on large polygons.

Boundary-fill Algorithm

It is also known as the “Edge-fill algorithm.” The boundary fill algorithm is used for area filling. We can perform boundary fill where we want to create an attractive painting. In this, we can easily select the interior points. If the object has a particular boundary in a single color, then the algorithm travels each pixel until it reaches the boundary.

Filled Area Primitives

In the Boundary-fill algorithm, we use the 4-connected and 8-connected methods. By the use of a 4-connected or 8-connected method, we can set the new position of the pixels until all the interior points have been filled.

Filled Area Primitives
Filled Area Primitives

Algorithm of Boundary-fill

Procedure boundary fill (p, q, fill color, boundary)

Step 1: Initialize the boundary of the region.

Step 2: Get the interior pixel (p, q). Now, define an Integer called current pixel and assign it to (p, q).

Current = getpixel (p, q)

Step 3: If

                   (current pixel != boundary) and (current pixel != fill)

            Then

                    Setpixel(p, q, fill);

Boundary fill (p+1, q, fill, boundary);

Boundary fill (p-1, q, fill, boundary);

Boundary fill (p, q+1, fill, boundary);

Boundary fill (p, q-1, fill, boundary);

Step 4: End;

Problems with Boundary-fill algorithm

  • Sometimes it may not fill all the regions.
  • In the 4-connected method, it does not fill corner pixels. Because it only checks the adjacent position of the pixel.

Scan-Line Algorithm

The Scan-Line Algorithm is an area filling algorithm. In this algorithm, we can fill the polygons through horizontal lines or scan lines. The scan-line intersects the edges of the polygon, and the polygon is filled between pairs of the intersection. The main purpose of this algorithm is to fill color in the interior pixels of the polygon.

Filled Area Primitives

Special Cases of Polygon Vertices

There are two special cases of polygon vertices which are given below:

  1. If both lines intersecting at the vertex lies on the same side of the scan line, then we will consider it as two points.
  2. If both lines intersecting at the vertex lies on the other side of the scan line, then we will consider it as a single point only.    

Algorithm of Scan line polygon-fill

Step 1: Find the intersection points of the scan line that have edges.

Step 2: Now sort the intersection points by increasing the x coordinate from left to right.

Step 3: Now, we perform the pairing of the intersection points and fill the color inside the pixel pairs.  


Related Topics

3D Reflection

The Reflection is a mirror image of the original object. We can differentiate 2D and 3D reflection by adding Z-axis. The Z-axis shows the depth of the surface. In the...

1 minute read.

Applications of Computer Graphics

Applications of Computer Graphics Some applications of computer graphics are mentioned below- Graphical User Interface (GUI): It is a way of interacting with a computer using the icon, ...

2 minutes read.

Polygon Clipping in Computer Graphics

“A Polygon can be described as the enclosed collection or group of the lines.” In a polygon, all lines are connected. Lines can be a combination of edges and vertices,...

4 minutes read.

Illumination Model in Computer Graphics

Illumination Model in Computer Graphics The series of methods used to depict light in computer graphics scenarios is computer graphics illumination. Although lighting strategies provide versatility in the degree of detail...

8 minutes read.

Scan Conversion of a Circle Computer Graphics

A circle is an eight-way symmetric shape. All quadrants of a circle are the same. There are two octants in each quadrant of a circle. If we know the value of any...

3 minutes read.

2D Scaling

In scaling, we can expend or compress the size of any object. We can apply scaling on the object by multiplying the original coordinates with scaling factors. The term scaling factor...

2 minutes read.

Image Representation in Computer Graphics

Image Representation: In computer science, we can represent an image in various forms. Most of the time, it refers to the way that brings information, such as color is coded digitally, and...

4 minutes read.

2D Transformation in Computer Graphics

Some visuals are transformed into some other graphics by implementing several of the principles known as transformation. There are multiple kinds of transformation, including translation, scaling, rotation, shearing, etc. Whenever...

2 minutes read.

Pointing and Positioning Technique Computer Graphics

Pointing and Positioning Technique: The pointing and positioning are interactions used in computer graphics. A pointing device is also called a Pointing tool. A pointing tool is a hardware component,...

4 minutes read.

Homogenous Coordinates in Computer Graphics

Homogenous Coordinates in Computer Graphics The orbit of a point, a line graph or the whole picture on the computer, a point besides the origin, is accomplished by first shifting the...

7 minutes read.

Anti-aliasing in Computer Graphics

Anti-aliasing in Computer Graphics “Anti-aliasing is a method for eliminating the aliasing effect used in computer graphics. In a 2-dimensional object, the ambient occlusion impact is the existence of sharp edges...

7 minutes read.

3D Translation

A 3D Translation process contains the x-axis, y-axis, and z-axis. We can move any object from one place to another without changing the shape of the object. For Example-Translation of a...

1 minute read.

3D Rotation

The 3D rotation is different from 2D rotation. In 3D Rotation we also have to define the angle of Rotation with the axis of Rotation. For Example- Let us assume, The initial...

2 minutes read.

Projection in Computer Graphics

Projection Introduction: The technique projection was invented by the Swiss mathematician, engineer, and astronomer "Leonhard Euler Around" in 1756. The "Episcope" was the first projection system. “Projection is a technique or process which...

4 minutes read.

Scan Conversion in Computer Graphics

“When we represent regular objects in the form of discrete pixels, it is called Scan Conversion.” Every graphics system must transform the primitives into a collection of pixels. The scan conversion is also...

2 minutes read.

Bresenham’s Line Drawing Algorithm in Computer Graphics

This algorithm was introduced by “Jack Elton Bresenham” in 1962. This algorithm helps us to perform scan conversion of a line. It is a powerful, useful, and accurate method. We...

8 minutes read.

Display Processor

It is a part of hardware or interpreter which is used to transform display processor code into pictures. It is used to convert digital information from CPU to analog data. It...

4 minutes read.

2D Rotation

The Rotation of any object depends upon the two points. Rotation Point: It is also called the Pivot point. Rotation Angle: It is denoted by Theta (). We can rotate an object in...

1 minute read.

3D Shearing

We can denote shearing with ‘SHx,’ ‘SHy,’ and ‘SHz.’ These ‘SHx,’ ‘SHy,’ ‘SHz’ are called “Shearing factor.” The basic difference between 2D and 3D Shearing is that the 3D plane also...

1 minute read.

Computer Graphics Window

“The process of selecting and viewing an image with different views, called windowing.” All the objects in the real world have a size. We can measure the size and location of...

4 minutes read.