0% found this document useful (0 votes)
19 views11 pages

Flood Fill Algorithm:: Disadvantage

The document discusses various algorithms for region filling in computer graphics, including the Flood Fill and Boundary Fill algorithms, which use recursive methods to fill areas with specified colors. It also covers 2D transformations, specifically 2D translation, explaining how to move objects in a two-dimensional plane using translation vectors and matrix representations. Additionally, it introduces the Mid-Point Ellipse Drawing Algorithm, which is used to calculate perimeter points of an ellipse, highlighting its advantages and disadvantages.

Uploaded by

brigcse05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views11 pages

Flood Fill Algorithm:: Disadvantage

The document discusses various algorithms for region filling in computer graphics, including the Flood Fill and Boundary Fill algorithms, which use recursive methods to fill areas with specified colors. It also covers 2D transformations, specifically 2D translation, explaining how to move objects in a two-dimensional plane using translation vectors and matrix representations. Additionally, it introduces the Mid-Point Ellipse Drawing Algorithm, which is used to calculate perimeter points of an ellipse, highlighting its advantages and disadvantages.

Uploaded by

brigcse05
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Flood Fill Algorithm:

In this method, a point or seed which is inside region is selected. This


point is called a seed point. Then four connected approaches or eight
connected approaches is used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But
this method is more suitable for filling multiple colors boundary. When
boundary is of many colors and interior is to be filled with one color we
use this algorithm.

In fill algorithm, we start from a specified interior point (x, y) and reassign
all pixel values are currently set to a given interior color with the desired
color. Using either a 4-connected or 8-connected approaches, we then
step through pixel positions until all interior points have been repainted.
Disadvantage:
1. Very slow algorithm
2. May be fail for large polygons
3. Initial pixel required more knowledge about surrounding pixels.
Algorithm:
1. Procedure floodfill (x, y,fill_ color, old_color: integer)
2. If (getpixel (x, y)=old_color)
3. {
4. setpixel (x, y, fill_color);
5. fill (x+1, y, fill_color, old_color);
6. fill (x-1, y, fill_color, old_color);
7. fill (x, y+1, fill_color, old_color);
8. fill (x, y-1, fill_color, old_color);
9. }
10. }

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.

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

Four connected approaches is more suitable than the eight connected


approaches.

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.

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

2D Transformation in Computer Graphics-

In Computer graphics,

Transformation is a process of modifying and re-positioning the existing graphics.

 2D Transformations take place in a two dimensional plane.


 Transformations are helpful in changing the position, size, orientation, shape etc of the
object.

3
Transformation Techniques-

In computer graphics, various transformation techniques are-

2D Translation in Computer Graphics-

In Computer graphics,
2D Translation is a process of moving an object from one position to another in a two dimensional
plane.

Consider a point object O has to be moved from one position to another in a 2D plane.
Let-
 Initial coordinates of the object O = (Xold, Yold)
 New coordinates of the object O after translation = (Xnew, Ynew)
 Translation vector or Shift vector = (Tx, Ty)

Given a Translation vector (Tx, Ty)-


 Tx defines the distance the Xold coordinate has to be moved.
 Ty defines the distance the Yold coordinate has to be moved.

4
This translation is achieved by adding the translation coordinates to the old coordinates of
the object as-
 Xnew = Xold + Tx (This denotes translation towards X axis)
 Ynew = Yold + Ty (This denotes translation towards Y axis)

In Matrix form, the above translation equations may be represented as-

 The homogeneous coordinates representation of (X, Y) is (X, Y, 1).


 Through this representation, all the transformations can be performed using matrix /
vector multiplications.

The above translation matrix may be represented as a 3 x 3 matrix as-

PRACTICE PROBLEMS BASED ON 2D TRANSLATION


IN COMPUTER GRAPHICS-

5
Problem-01:

Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with
distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C without
changing its radius.

Solution-

Given-
 Old center coordinates of C = (Xold, Yold) = (1, 4)
 Translation vector = (Tx, Ty) = (5, 1)

Let the new center coordinates of C = (Xnew, Ynew).

Applying the translation equations, we have-


 Xnew = Xold + Tx = 1 + 5 = 6
 Ynew = Yold + Ty = 4 + 1 = 5

Thus, New center coordinates of C = (6, 5).

Alternatively,

In matrix form, the new center coordinates of C after translation may be obtained as-

Thus, New center coordinates of C = (6, 5).

6
Problem-02:

Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the translation
with distance 1 towards X axis and 1 towards Y axis. Obtain the new coordinates of the
square.

Solution-

Given-
 Old coordinates of the square = A (0, 3), B(3, 3), C(3, 0), D(0, 0)
 Translation vector = (Tx, Ty) = (1, 1)

For Coordinates A(0, 3)

Let the new coordinates of corner A = (Xnew, Ynew).

Applying the translation equations, we have-


 Xnew = Xold + Tx = 0 + 1 = 1
 Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner A = (1, 4).

For Coordinates B(3, 3)

Let the new coordinates of corner B = (Xnew, Ynew).

Applying the translation equations, we have-

7
 Xnew = Xold + Tx = 3 + 1 = 4
 Ynew = Yold + Ty = 3 + 1 = 4

Thus, New coordinates of corner B = (4, 4).

For Coordinates C(3, 0)

Let the new coordinates of corner C = (Xnew, Ynew).

Applying the translation equations, we have-


 Xnew = Xold + Tx = 3 + 1 = 4
 Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner C = (4, 1).

For Coordinates D(0, 0)

Let the new coordinates of corner D = (Xnew, Ynew).

Applying the translation equations, we have-


 Xnew = Xold + Tx = 0 + 1 = 1
 Ynew = Yold + Ty = 0 + 1 = 1

Thus, New coordinates of corner D = (1, 1).


Thus, New coordinates of the square = A (1, 4), B(4, 4), C(4, 1), D(1, 1).

8
To gain better understanding about 2D Translation in Computer Graphics,

Mid-Point Ellipse Algorithm in Computer


Graphics
What is an ellipse?
Ellipse is defined as the geometric figure which is the set of all points on a
plane whose distance from two fixed points known as the foci remains a
constant.

It consists of two axes: major and minor axes where the major axis is the
longest diameter and minor axis is the shortest diameter.

Unlike circle, the ellipse has four-way symmetry property which means
that only the quadrants are symmetric while the octants are not.

9
Here, we will calculate the points for one quadrant while the points for the
remaining three can be calculated using the former points.

Introduction to the Mid-Point Ellipse Drawing


Algorithm
In computer graphics, the mid-point ellipse algorithm is an
incremental method of drawing an ellipse. It is very similar to the mid-
point algorithm used in the generation of a circle.

The mid-point ellipse drawing algorithm is used to calculate all the


perimeter points of an ellipse. In this algorithm, the mid-point between
the two pixels is calculated which helps in calculating the decision
parameter. The value of the decision parameter determines whether the
mid-point lies inside, outside, or on the ellipse boundary and the then
position of the mid-point helps in drawing the ellipse.

Working of the Mid-Point Ellipse Drawing


Algorithm
Now, for understanding the proper working of the algorithm, let us
consider the elliptical curve in the first quadrant.

Also, consider the equation of ellipse:

ry2 x2 + rx2 y2 - rx2 ry2 = 0 ...(1)


where, ry : semi-minor axis
rx : semi-major axis

In the ellipse each quadrant is divided into two


regions: R1 and R2 respectively.

We know that the slope of an ellipse is given by:

m =dx / dy = - (2 ry2 x /2 rx2 y ) = -1

The region R1 has the value of slope as m<-1 while R2 has the value of
slope as m > -1.

The starting point for R1 will be (0, ry) and for R2, the initial points will
become the ending points of R1, where the slope becomes greater than -
1. Thats why we need to keep in check the value of slope while plotting
the points for R1 to know whether we have reached R2 or not.

10
Advantages:

 The mid-point ellipse algorithm has simple and easy implementation


as it only includes addition operations.

Disadvantages:

 This algorithm is time consuming.

11

You might also like