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

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.

Mid-Point Line Drawing Algorithm in Computer Graphics

The Mid-point Subdivision algorithm is the extension of the Cyrus-Beck algorithm. The Mid-Point line plotting algorithm was introduced by “Pitway and Van Aken.” It is an incremental line drawing algorithm....

8 minutes read.

Scan Conversion of an Ellipse Computer Graphics

Scan Conversion of an Ellipse: An ellipse can be defined as a closed plane curve, which is a collection of points. It is the cause of the intersection of a...

8 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.

Line Clipping in Computer Graphics

The line clipping is a process in which we can cut the part of the line, which lies outside the view pane. Only those lines are visible, which lie inside the view pane....

13 minutes read.

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...

4 minutes read.

3d Scaling

The 2D and 3D scaling are similar, but the key difference is that the 3D plane also includes the z-axis along with the x and y-axis. In scaling, we can expend...

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.

Types of Computer Graphics

Types of Computer Graphics The computer graphics contains two types. They are- Raster (Bitmap) graphicsVector graphics Many individuals are likely to consider pictures on computers (or phones, tablets, or some other electronic gadget...

5 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.

Input Devices in Computer Graphics

An Input device is the piece of computer hardware equipment used to give input to the computer. The input can be in the form of graphics, text, sound, audio, video,...

7 minutes read.

2D Reflection

The Reflection is a mirror image of the original object. In the Reflection process, the size of the object does not change. We can represent Reflection by using four ways- Reflection along...

2 minutes read.

Computer Graphics Tutorial

Introduction to Computer Graphics Computer graphics is commonly seen as a computer science branch that deals with the computerized image fusion theory and technology. As simple as a triangle outline, a...

6 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.

Composite Transformation in Computer Graphics

Composite transformation in Computer Graphics It is possible to integrate a range of transformations or series of transformations into some kind of a single one which is known as composition. The...

6 minutes read.

Aspect Ratio in Computer Graphics

Aspect Ratio in Computer Graphics You might well understand the concept of Aspect ratio as of now if you know regarding aerial photography or see the configuration portion of any computer...

5 minutes read.

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.

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.

Animation in Computer Graphics

The word Animation is extracted from a Latin language, "Anima," which means "Soul." TheAnimation is a technology that allows any image object, an entity to walk, talk, or do some...

3 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.