0% found this document useful (0 votes)
16 views32 pages

Unit 2 Revised

Uploaded by

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

Unit 2 Revised

Uploaded by

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

Bsc.

Csit-notes by : Bindu Aryal

Unit 2: Scan Conversion Algorithm (6 Hrs.)


2.1 Scan Converting a Point and a straight Line: DDA Line Algorithm, Bresenham’s Line
Algorithm
2.2 Scan Converting Circle and Ellipse: Mid-Point Circle and Ellipse Algorithm
2.3 Area Filling: Scan Line Polygon fill Algorithm, Inside-outside Test, Scan line fill of Curved
Boundary area, Boundary-fill and Flood-fill algorithm

Scan Conversion Algorithm:


“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 called “Rasterization.” Each pixel
in the graphical system has two states either on or off.

In, computer graphics, an image on the screen is displayed by illuminating


(enlightening) the pixels at appropriate locations on the screen. This is done by
storing the pictures definition in the refresh buffer of the display device which is
read by the video controller circuitry of the computer and accordingly voltage
applied to the control grid and deflection plates are varied to get “on” the
desired pixel. This process of plotting the object on the screen is called Scan
Conversion.
Examples of objects which can be scan converted
• Point
• Line
• Arc
• Ellipse
• Rectangle
• Polygon
• Characters
• Filled Regions
The algorithms implementation varies from one computer system to another
computer system. Some algorithms are implemented using the software. Some
are performed using hardware or firmware. Some are performed using various
combinations of hardware, firmware, and software.

1. Scan Converting a Point:

Pixel

1
Bsc.Csit-notes by : Bindu Aryal

“We can define a pixel as a rectangular dot centered at an integral position


on an integral grid.” It is a real point that is addressable. The pixel is also
called “picture element (Pel).”

A pixel includes its own:

 Intensity – The intensity of a pixel defines the brightness of the image that
appears on the screen.
 Name or Address- The name or address of a pixel defines the position of the
pixel.
We can define the size of any image with a total number of horizontal pixels
and the total number of vertical pixels.
For Example- (512 x 512, 640 x 480, or 1024 x 768).
We can measure the ratio of an image’s width to its height in unit length or
number of pixels, is known as the aspect ratio of the image.

Each pixel on the graphics display does not represent a mathematical point.
Instead, it means a region which theoretically can contain an infinite number of
points. Scan-Converting a point involves illuminating the pixel that contains the
point.

2
Bsc.Csit-notes by : Bindu Aryal

To illuminate a pixel position at the calculated coordinate position, we shall have


a function available in the implemented programming language of the form:

PlotPixel(x,y)

2. Scan Converting a straight Line:


A straight line may be defined by two endpoints & an equation. In fig the two
endpoints are described by (x1,y1) and (x2,y2). The equation of the line is used to
determine the x, y coordinates of all the points that lie between these two
endpoints.

Using the equation of a straight line, y = mx + b where m = Scan Converting a


Straight Line & b = the y interrupt, we can find values of y by incrementing x from
x =x1, to x = x2. By scan-converting these calculated x, y values, we represent the
line as a sequence of pixels.

3
Bsc.Csit-notes by : Bindu Aryal

4
Bsc.Csit-notes by : Bindu Aryal

5
Bsc.Csit-notes by : Bindu Aryal

6
Bsc.Csit-notes by : Bindu Aryal

Bresenham’s Line Algorithm :

7
Bsc.Csit-notes by : Bindu Aryal

8
Bsc.Csit-notes by : Bindu Aryal

9
Bsc.Csit-notes by : Bindu Aryal

10
Bsc.Csit-notes by : Bindu Aryal

Fig: 8 way symmetry of circle.

Equation of circle:
X2+y2=r2

11
Bsc.Csit-notes by : Bindu Aryal

Where d= decision parameter

12
Bsc.Csit-notes by : Bindu Aryal

13
Bsc.Csit-notes by : Bindu Aryal

14
Bsc.Csit-notes by : Bindu Aryal

15
Bsc.Csit-notes by : Bindu Aryal

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 plane over a cone. The ellipse is a symmetric
shape figure. It is similar to a circle, but it contains four-way symmetry. We can
also define an ellipse as a closed curve created by the points moving in such an
order that the total of its distance from two points is constant. These two points
are also called “foci.”
Properties of Ellipse:

The circle and ellipse are examples of the conic section.


We can create an ellipse by performing stretching on a circle in x and y-direction.
Every ellipse has two focal points, called “foci.” In the standard form, we can write
the ellipse equation as follow-

(h, k) are the center coordinates of the circle.

There should be two axes of an ellipse.

 Major axis
 Minor axis
Major axis: The major axis is the longest width. For a horizontal ellipse, the major
axis and x-axis are parallel to each other. 2a is the length of the major axis. The
endpoints of the major axis are vertices with (h ±a, k).

Minor axis: The minor axis is the shortest width of it. For a horizontal ellipse, the
minor axis is parallel to the y-axis. 2b is the length of the minor axis. The
endpoints of the minor axis are vertices with (h, k ±a).

16
Bsc.Csit-notes by : Bindu Aryal

Mid Point ellipse drawing Algorithm:

Function of ellipse:

17
Bsc.Csit-notes by : Bindu Aryal

10.stop calculation in second octant as soon as x=rx and y=0.

Calculations:

18
Bsc.Csit-notes by : Bindu Aryal

19
Bsc.Csit-notes by : Bindu Aryal

Area Filling:
A standard output primitive in general graphics package is solid color or
patterned polygon area. Other kinds of area primitives are sometimes available,
but polygons are easier to process since they have linear boundaries. There are
two basic approaches to area filling in raster systems. One way to fill an area is to
determine the overlap intervals for scan lines that cresses the area. Another
method for area filling is to start from a given interior position and point outward
from this until a specified boundary is met.

Scan line polygon fill Algorithm:

20
Bsc.Csit-notes by : Bindu Aryal

Now final step make pair of intersection:


We get 2 pair (6,12),(16,20).
And fill the pixel with color within pair.

21
Bsc.Csit-notes by : Bindu Aryal

Points (8,12),(12,14).

22
Bsc.Csit-notes by : Bindu Aryal

Special handling
- Intersection is an edge end point

23
Bsc.Csit-notes by : Bindu Aryal

24
Bsc.Csit-notes by : Bindu Aryal

Intersection points along scan line y' correctly identify the interior pixel
spans. But with scan line y, we need to do some additional processing to
determine the correct interior points. For scan line y, the two edges sharing
the intersecting vertex are on opposite side of the scan-line. But for scan-line
y' the two edges sharing intersecting vertex are on the same side (above) the
scan line position. So the vertices those are on opposite side of scan line
require extra processing. We can identify these vertices by tracing around
the polygon boundary either in clockwise or counter clockwise order and
observing the relative changes in vertex y coordinates as we move from one
edge to next. If the endpoint y values of two consecutive edges
monotonically increases or decrease, we need to count the middle vertex as
a single intersection point for any scan line passing through that vertex.
Otherwise the shared vertex represents a local extremum (minimum or
maximum) on the polygon boundary, and the two edge intersections with
the scan-line passing through that vertex.
scan-line passing through that vertex.

25
Bsc.Csit-notes by : Bindu Aryal

Line y'
(a) (b)
In line y, tracing along edge the y-coordinate of one edge increasing in (a)
and the other edge is decreasing in (b) so this vertex is count as a single
intersection point for the scan-line fill algorithm.
1. If both lines intersecting at the vertex are on the same side of the scan line,
consider it as two points.
2. If lines intersecting at the vertex are at opposite sides of the scan line,
consider it as only one point.

Inside outside test

26
Bsc.Csit-notes by : Bindu Aryal

Scan-Line Fill of Curved Boundary area


It requires more work than polygon filling, since intersection calculation
involves nonlinear boundary for simple curves as circle, eclipses, performing
a scan line fill is straight forward process. We only need to calculate the two
scan-line intersection on opposite sides of the curve. then simply fill the
horizontal spans of pixel between the boundary points on opposite side of
curve. Symmetries between quadrants are used to reduce the boundary
calculation we can fill generating pixel position along curve boundary using
mid -point method.

27
Bsc.Csit-notes by : Bindu Aryal

Boundary-fill Algorithm:
Boundary fill is the algorithm used frequently in computer graphics to fill a
desired color inside a closed polygon having the same boundary color for all
of its sides. In Boundary filling algorithm starts at a point inside a region and
paint the interior outward the boundary. If the boundary is specified in a
single color, the fill algorithm proceeds outward pixel by until the boundary
color is reached. A boundary-fill procedure accepts as input the co-ordinates
of an interior point (x,y), a fill color, and a boundary color. Starting from (x,y),
the procedure tests neighboring positions to determine whether they are of
boundary color. If not, they are painted with the fill color, and their
neighbors are tested. This process continue until all pixel up to the boundary
color area have tested. The neighboring pixels from current pixel are
proceeded by two method: 4- connected if they are adjacent horizontally and
vertically. 8- connected if they adjacent horizontally, vertically and
diagonally.

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

28
Bsc.Csit-notes by : Bindu Aryal

 Eight connected approach: In this approach, left, right, above, below and
four diagonals are selected.
Recursive boundary-fill algorithm not fill regions correctly if some interior
pixels are already displayed in the fill color. Encountering a pixel with the fill
color can cause a recursive branch to terminate, leaving other interior pixel
unfilled. To avoid this we can first change the color of any interior pixels that
are initially set to the fill color before applying the boundary fill procedure.

Flood-fill Algorithm:
Flood-fill Algorithm is applicable when we want to fill an area that is not
defined within a single color boundary. If fill area is bounded with different

29
Bsc.Csit-notes by : Bindu Aryal

color, we can paint that area by replacing a specified interior color instead of
searching of boundary color value. This approach is called flood fill algorithm.
We start from a specified interior pixel (x,y) and reassign all pixel values that
are currently set to a given interior color with desired fill_color. Using either
4-connected or 8-connected region recursively starting from input position,
The algorithm fills the area by desired color.
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.

30
Bsc.Csit-notes by : Bindu Aryal

Condition: current pixel=old color

Use 8 connected approach:


To overcome problems in

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:

31
Bsc.Csit-notes by : Bindu Aryal

 Very slow algorithm


 May be fail for large polygons
 Initial pixel required more knowledge about surrounding pixels.

Algorithm:

32

You might also like