0% found this document useful (0 votes)
66 views

Computer Graphics Chapter-3

This document discusses scan conversion algorithms used to display graphic objects on raster displays. It covers algorithms for drawing points, lines, circles and antialiasing. For lines, it describes the Digital Differential Analyzer (DDA) and Bresenham's line algorithms which use integer calculations to efficiently determine which pixels to turn on to approximate a line. It also summarizes Bresenham's circle drawing algorithm and discusses antialiasing techniques to reduce jagged edges.

Uploaded by

abdi geremew
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Computer Graphics Chapter-3

This document discusses scan conversion algorithms used to display graphic objects on raster displays. It covers algorithms for drawing points, lines, circles and antialiasing. For lines, it describes the Digital Differential Analyzer (DDA) and Bresenham's line algorithms which use integer calculations to efficiently determine which pixels to turn on to approximate a line. It also summarizes Bresenham's circle drawing algorithm and discusses antialiasing techniques to reduce jagged edges.

Uploaded by

abdi geremew
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

Chapter Three

Scan Conversion Algorithms


Contents
Introduction
Point and Lines
Line drawing algorithms
Circle drawing algorithms
Antialiasing
Character generation
Introduction
The major objective of computer graphics is to model graphic objects in
a scene.
Such objects comprise entity primitives like point, line, circle, ellipse
and curves.
For displaying these entities on a raster display the representative sets
of pixels of the appropriate intensity or colour must be identified.
There are standard scan conversion algorithms to calculate first the
position coordinates of the representative pixels of each entity primitive
from basic input data and then store pixel-wise intensity information
into the graphics memory.
Points and lines
In order to draw the primitive objects, one has to first scan convert
the objects.
This refers to the operation of finding out the location of pixels to be
intensified and then setting the values of corresponding bits, in the
graphics memory, to the desired intensity code.
Each pixel on the display surface has a finite size depending on the
screen resolution and hence a pixel cannot represent a single
mathematical point.
Points and lines …
However, we consider each pixel as a unit square area identified by
the coordinate of its lower left corner, the origin of the reference
coordinate system being located at the lower left corner of the display
surface.
 Thus each pixel is accessed by a non-negative integer coordinate pair
(x, y).
The x values start at the origin and increase from left to right along a
scan line and the y values (i.e., the scan line numbers) start at bottom
and increase upwards.
Points and lines …
Line drawing is accomplished by calculating intermediate point
coordinates along the line path between two given end points.
Since screen pixels are referred with integer values, plotted positions
may only approximate the calculated coordinates – i.e., pixels which
are intensified are those which lie very close to the line path if not
exactly on it which is in the case of perfectly horizontal, vertical or 45°
lines only.
Standard algorithms are available to determine which pixels provide
the best approximation to the desired line.
Points and lines …
Still, screen resolution is a big factor towards improving the
approximation.
In a high resolution system the adjacent pixels are so closely spaced
that the approximated line-pixels lie very close to the actual line path
and hence the plotted lines appear to be much smoother — almost
like straight lines drawn on paper.
In a low resolution system, the same approximation technique causes
lines to be displayed with a ‘stairstep appearance’ – not smooth.
Points and lines …
Array of Square Pixels on the Display Surface. Coordinate of pixel A: 0,
0; B: 2, 2; C: 6,7. A coordinate position (6.6,7.25) is represented by C,
whereas (2.3,2.5) is represented by B. For plotting on the screen, the
calculated pixel coordinates are rounded off to nearest integers.
Points and lines …
Line drawing algorithms
Several line drawing algorithms are developed with the basic
objective to create visually satisfactory images in least possible time.
This is achieved by reducing the calculations to a minimum preferably
using integer rather than floating point arithmetic.
Such ways of minimizing even a single arithmetic operation is so
important, because every drawing or image generated will have a
large number of line segments in it and every line segment will have
many pixels.
Line drawing algorithms …
So saving of even one computation per pixel will save number of
computations in generating an object, which, in turn, minimizes the
time required to generate the whole image on the screen.
Here, we will discuss DDA and Bresenham’s algorithms, which scan
converts lines with acceptable approximation in sufficiently less time.
In order to draw a line on the screen, first we have to determine
which pixels have to switch ON or OFF to be highlighted.
The process of determining which combination of pixels provides the
best approximation to the desired line is known as rasterization.
Line drawing algorithms …
General requirements for drawing a line are:
 Lines must appear to be straight.
 Lines should start and end accurately.
 Lines should have constant brightness along their length.
 Lines should be drawn rapidly.
Cartesian slope-intercept equation for a straight line is y=mx + c ---(1)
Given line end point (x1, y1) and (x2, y2), m=(y2-y1)/(x2-x1)------- (2)
Line drawing algorithms …
c=y1-(m.x1)----- (3)
Algorithms for displaying straight lines are based on the equations
(1), (2) and (3).
∆y=m. ∆x------ (4)
∆x= ∆y/m---- (5)
DDA Algorithm
DDA is a scan-conversion line algorithm based on either ∆y or ∆x, using
equation (4) or (5).
DDA line drawing algorithm can be written as:-
Step 1. Input the two line end points (xa , ya) and (xb, yb )
Step 2. Calculate dx = xb – xa; dy = yb - ya
Step 3. If abs(dx)>=abs(dy) then Length= abs(dx)
else
Length= abs(dy); ∆x=dx/length; ∆y=dy/length; x=xa; y=ya;
putpixel(ceil(x),ceil(y)); i=1;
DDA Algorithm …
Step 4. while (i<=length)
x=x+∆x; y=y+∆y; putpixel(ceil(x),ceil(y)); i=i+1;
end while
Step 5. Finish
DDA Algorithm …
Drawbacks of DDA Algorithm
 Although DDA is fast, the accumulation of round off error in successive
additions of floating point increment however can cause the calculated pixel
position to drift away from the true line path for the long line segments.
 Floating point operations and rounding off in DDA is time consuming.
DDA Algorithm …
Exercise:
1.Consider a line from (2, 3) to (6, 6). Use DDA algorithm to rasterize this line.
2.Consider a line from (0,0) to (6,7). Use DDA algorithm to rasterize this line.
Then draw a line on paper using (x, y) coordinates.
3.Consider a line from (0, 0) to (-5, 5). Use DDA algorithm to rasterize this line.
Then draw a line on paper using (x, y) coordinates
Bresenham's Line Algorithm
An accurate and efficient raster line generating algorithm, developed
by Bresenham, scan converts lines using only incremental integer
calculations that can be adapted to display circles and other curves.
We can summarize Bresenham's line drawing for a line with positive
slope less than 1 in the following listed steps.
The constants 2∆Y and 2∆Y-2∆X are calculated once for each line to
be scan converted, so the arithmetic involves only integer addition
and subtraction of these two constants.
Bresenham's line drawing algorithm for |m|< 1:
Bresenham's Line Algorithm …
Step 1: Input the two endpoints (xa , ya) and (xb, yb) and store the
left endpoint in (x0,y0)
Step 2: Load (x0,y0) into the frame buffer: that is , plot the first point.
Step 3: Calculate constants ∆x= xb-xa, ∆y= yb-ya, 2∆y, and 2∆y-2∆x
and obtain the starting point for the decision parameter as:
 P0= 2∆y-∆x

Step 4: At each Xk along the line, starting at K=0; perform the


following test:
Bresenham's Line Algorithm …
 If pk < 0
• Xk+1 = xk +1 and yk+1 = yk
• pk+1 = pk + 2∆y
 otherwise, if pk > 0
• Xk+1 = xk +1 and yk+1 = yk + 1
• pk+1 = pk + 2∆y-2∆x

Step 5: Repeat step 4, ∆x times


Exercise: Consider a line from (2, 3) to (6, 6). Use Bresenham’s line
drawing algorithm to rasterize this line.
Bresenham's Circles Algorithm
An accurate and efficient raster scan circle generating algorithm, developed
by Bresenham, scan converts circle using only incremental integer
calculations that can be adapted to display and other curves also.
Bresenham's Circles Algorithm:
Step 1. Input radius and circle center (Xc,Yc), and obtain the first point on
the circumstances of a circle centered on the origin as (X0,Y0)=(0,r)

Step 2. Calculate initial values of decision parameter as P0=3-2*r

Step 3. At each Xk along the line, starting at K=0, perform the following test:
Bresenham's Circles Algorithm …
 If pk < 0 then
• Xk+1 = xk +1 and yk+1 = yk
• pk+1 = pk + 4 Xk+1 + 6
 otherwise, if pk > 0
• Xk+1 = xk +1 and yk+1 = yk - 1
• pk+1 = pk + 4(Xk+1 - yk+1) + 10
• Step 4. Determine symmetry points at the other seven octants
• Step 5. Move each calculated pixel position (x,y) onto the circular path
centered on (Xc,Yc) and plot the coordinate value as x=x+xc and y=y+yc
Bresenham's Circles Algorithm …
Step 6. Repeat step 3 to 5 until x>=y.
Exercise:
1. Consider a line from (2, 3) to (6, 6). Use Bresenham's line drawing
algorithm to rasterize this line.
2. Draw a line with end points (20,10) and (30,18) using Bresenham’s
line drawing algorithm.
Antialiasing
If you try to implement the various scan conversion algorithms
discussed so far in a computer you will soon discover that sometimes
same pixel is unnecessarily set to same intensity multiple times;
sometimes some objects appear dimmer or brighter though all are
supposed to have same intensity; and most of the objects generated
are not smooth and appear to have rough edges.
All these are standard side effects of scan conversion: the first type is
called over striking effect, the second is unequal intensity effect while
the third type which is the most common and most pronounced,
known as aliasing effect.
Antialiasing …
In fact, aliasing is a typical image quality problem on all pixel devices,
including a computer screen.
Aliasing is the stair-step effect or jaggies on the edges of objects
displayed on computer screens – all diagonal and curved lines are
displayed as a series of little zigzag horizontal and vertical lines and
can be extremely distracting for PC users.
Antialiasing …
Antialiasing …
Among the other effects of aliasing, jagged profiles and disintegrating
textures are very common.
Antialiasing …
These jaggies are essentially caused by the problem of trying to map a
continuous image onto a discrete grid of pixels.
This continuous-to-discrete transformation (known as scan conversion) is
performed by sampling the continuous line, curve etc. at discrete points
(integer pixel positions) only followed by generating image pixels at integer
locations that only approximate the true location of the sampled points.
Pixels so generated at alias locations constitute aliases of the true objects
or object edges.
Therefore, we can say aliasing occurs as a result of an insufficient sampling
rate and approximation error (or more specifically quantization error).
Antialiasing …
In fact, aliasing is a potential problem whenever an analog signal is
point sampled to convert it into a digital signal.
It can occur in audio sampling, for example, in converting music to
digital forms to be stored on a CD-ROM or other digital devices.
Whenever an analog audio signal is not sampled at a high enough
frequency*, aliasing manifest itself in the form of spurious low
frequencies.
Now coming to Antialiasing, quite obviously it implies the techniques
used to diminish the jagged edges of an image so that the image
appears to have smoother lines.
Antialiasing …
As aliasing problem is due to low sampling rate for low resolution,
one easy solution is to increase the resolution, causing sample points
to occur more frequently.
This in turn will reduce the size of the pixels.
The size of the ‘jaggy’ or stair-step error is never larger than the size
of the actual pixel.
Hence, reducing the size of the pixel reduces the size of these steps.
But the cost of image production becomes higher with increased
resolution as it calls for more graphics memory.
Antialiasing …
The computational overhead increases for maintaining a high frame
rate (60 fps) for bigger frame buffer.
Thus, within the present limitations of hardware technology
increased screen resolution is not a feasible solution.
There are quite a few standard methods for antialiasing.
What antialiasing basically does is change the pixels around the edges
to intermediate colors or grayscales.
This has the effect of making the edges look smoother although it
also makes them fuzzier.
Antialiasing …
Antialiasing … (Super sampling or Postfiltering)
One of the methods of antialiasing is Super sampling or Postfiltering.
In this method more than one sample is sampled per pixel. How?
Every pixel area on the display surface is assumed to be subdivided
into a grid of smaller subpixels (super samples).
Thus, the screen is treated as having higher resolution than what
actually is.
A virtual image is calculated at this higher spatial resolution and then
mapped (displayed) to the actual frame resolution after combining
(averaging) the results of the subpixels.
Antialiasing … (Super sampling or Postfiltering)
The intensity value of a pixel is the average of the intensity values of
all the sampled subpixels within that pixel.
The following illustration describes the concept of super sampling.
Antialiasing … (Super sampling or Postfiltering)
Antialiasing … (Super sampling or Postfiltering)
Antialiasing … (Super sampling or Postfiltering)
Antialiasing … (Super sampling or Postfiltering)
This method is also known as postfiltering because filtering is carried
out after sampling.
Filtering means eliminating the high frequencies, i.e., combining the
super samples to compute pixel colour.
This type of filtering is known as unweighted filtering because each
super sample in a pixel, irrespective of its position, has equal
influence in determining the pixel’s colour.
 In other words, an unweighted filter computes an unweighted
average. The other type of filter is a weighted filter.
Antialiasing … (Super sampling or Postfiltering)
Through this filter each super sample is multiplied by its
corresponding weight and the products are summed to produce a
weighted average, which is used as the pixel colour.
The weighting given to each sample should depend in some way on
its distance from the center of the pixel.
The center sample within a pixel has maximum weight.
An array of values specifying the relative importance (weights) of
subpixels can be set for different-sized grids and is often referred to as
Pixel-Weighting Masks.
Antialiasing … (Area Sampling or Prefiltering)
The other standard method of antialiasing is Area Sampling or
Prefiltering.
Prefiltering method treats a pixel as an area, and computes pixel
colour based on the overlap of the scene’s objects with a pixel’s area.
These techniques compute the shades of grey based on how much of
a pixel’s area is covered by an object.
Compared to postfiltering, prefiltering technique doesn’t take into
account calculating subpixel intensities (thus eliminates higher
frequencies) before determining pixel intensities.
Antialiasing … (Area Sampling or Prefiltering)
A better technique, weighted area sampling uses the same basic
approach, but gives greater weight to area near the center of the
pixel.
Prefiltering thus amounts to sampling the shape of the object very
densely within a pixel region.
For shapes other than polygons, this can be very computationally
intensive.
Antialiasing …
There are other methods as well besides these two like Adaptive
Sampling, Stochastic Sampling, Raytracing etc.
But as an introduction to this topic we may stop here now.
However, it should be noted that aliasing is an inherent part of any
discrete process, its effect can be minimized but not eliminated.
Character generation
There are three basic methods to generate characters on a computer
screen:
(1). hardware-based
(2). vector-based and
(3). bit map-based methods.
Character generation … (Hardware-based)
In the hardware-based method, the logic for generating character is
built into the graphics terminal.
Though the generation time is less the typefaces* are limited due to
hardware restrictions.
Character generation … (Vector-based)
In the vector-based method the characters are developed using a set
of polylines and splines that approximates the character outline.
This form of character representation is completely device-
independent.
Memory requirement is less as boldface, italics or different size can
be produced by manipulating the curves outlining the character
shapes – it doesn’t require separate memory blocks for each
variation.
Character generation … (Vector-based)
Character generation … (Bitmap-based)
In the bitmap-based method small rectangular bitmap called
character mask (containing binary values 1 and 0) is used to store
pixel representation of each character in a framebuffer area known as
font cache.
Relative pixel locations corresponding to a character bitmap are
marked depending on the size, face and style (font) of character.
Size of each character masks range from 5 × 7 to 10 × 12.
A single font in 10 different font sizes and 4 faces (normal, bold, italic,
bold italic) would require 40 font caches.
Character generation … (Bitmap-based)
Characters are actually generated on display by copying the appropriate
bitmaps from the frame buffer to the desired screen positions.
A mask is referenced by the coordinate of the origin (lower left corner)
of the mask w.r.t frame buffer addressing system.
In bit map-based method a bold face character is obtained by writing
the corresponding ‘normal’ character mask in consecutive frame buffer
x-locations.
Italics character is produced by necessary skewing of ‘normal’ character
mask while being written in the frame buffer.
Character generation … (Bitmap-based)
In fact, a typeface designer can create from scratch new fonts using a
program like Windows Paint.
The overall design style (font and face) for a set of characters is called
a typeface.
The End

Any Questions?

You might also like