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

Scan Conversion

The document discusses scan conversion, a process of rasterizing graphics objects into pixels, highlighting issues like aliasing, unequal intensity, overstriking, and local/global aliasing. It also covers line drawing algorithms, specifically Bresenham's and Digital Differential Analyzer (DDA), detailing their assumptions, derivations, and algorithms for accurately plotting lines and circles. Techniques such as antialiasing are mentioned to mitigate visual artifacts in raster displays.

Uploaded by

h9179624
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)
9 views11 pages

Scan Conversion

The document discusses scan conversion, a process of rasterizing graphics objects into pixels, highlighting issues like aliasing, unequal intensity, overstriking, and local/global aliasing. It also covers line drawing algorithms, specifically Bresenham's and Digital Differential Analyzer (DDA), detailing their assumptions, derivations, and algorithms for accurately plotting lines and circles. Techniques such as antialiasing are mentioned to mitigate visual artifacts in raster displays.

Uploaded by

h9179624
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/ 11

SCAN CONVERSION

Since picture positions are at integer values, line can not be drawn from one addressable
point to another addressable point. Here we need to make certain approximation as to
which as pixel is to be fitted up at a time. Thias is called Rasterization/ Antialiasing/
Jaggies. The process of rasterization in scan-line order is called scan conversion. In other
words “the process of representing graphics object as a collection of pixel is called scan
conversion.”

Side effects of scan conversion:


(1) Aliasing : The term aliasing refers to the plotting of a point in a location other
than its true location in order to fit the point into the raster. Suppose the equation
of line is y=mx+c, where c=1, m=0.5 and x=3; solving for y, the true point is
(3,2.5). However, the raster does not contain the fractional location, so the point is
plotted at the alias location (3,3) as shown in figure :
Y
3
2
1

0 1 2 3 X

(2) Unequal intensity : The unequal intensity problem occurs because human
perception of light is dependent on both the density and the intensity of a light
source. Thus, on a raster display with perfect squareness, a diagonal line of pixels
will appear dimmer than a horizontal or vertical line. As can be seen in figure, the
pixels on the horizontal line are placed 1 unit apart, while the pixels on the
diagonal line are approximately 1.414 unit apart. This difference in density
produces the perceived difference in brightness. Software designers can respond
to this problem in one of three ways :
(a) If speed of scan conversion is of primary importance, the unequal intensity
problem can be ignored.
(b) The unequal intensity of the lines can be corrected by increasing the
number of pixels used to generate the diagonal line.
(c) The unequal intensity problem can be corrected by increasing the intensity
of pixels plotted on the diagonal.

Figure:
Y

√2

1 X
(3) Overstriking : Overstriking means same pixel is written to more than once. As a
result of overstriking, the speed of output is slightly degraded because time is
spent in scan converting the same point two or more times.
(4) Local or Global aliasing (the picket fence problem) : The picket fence problem
occurs when a user attempts to scan convert an object that will not fit exactly onto
the raster.
The computer graphics software designer must decide whether to use local
or global aliasing. With local aliasing, the distance between pickets in the picket
fence will be kept as close to their true relative distances as possible. However,
the overall length of the fence will be distorted.
When the global aliasing is used, the overall length of the picket fence will
be approximately correct but the spacing between pickets will be distorted.
The ever-increasing resolution of graphics system is slowly evolving
“backdoor” solution to the problem of aliasing. That is, pixel density is rapidly
approaching the resolution of the human eye at normal viewing distance, thus
making it impossible for a person to perceive aliasing.
Figure :

Original picture Local aliasing Global aliasing

Antialiasing of lines :
Many displays allow only two pixel states, on or off. For these displays, line may
have Jagged or stair-step appearance when they step from one row or column to the next.
The lower the resolution, the more apparent the effect. This is one aspect of a
phenomenon called aliasing.
Displays allow setting pixels to gray levels between black and white provide a
means to reduce this effect. The technique is called antialiasing, and it uses the gray
levels to gradually turn off the pixels in one row as it gradually turns on the pixels in the
next.
For gentle slop lines, we in effect examined the line position for each column
index and decided which row was closest. The line segment would lie between two
pixels, and we picked one. Suppose instead of picking the closest, we turned them both
on. We should choose the intensity values according to a function of distance between the
pixel index and the linre segment so that the pixel closest to the line receives most of its
intensiyty. The sum of the intensity values for the two pixels should match the total
intensity value for the line. The function used can be a simple or a complex expression
based on intensity patterns, pixel shapes and how lines cover them. In general, we want
the pixel’s intensity to match the amount of the line which covers its area.
Figure:
Y

1-H 1-H
H H
1-H
H

LINE-DRAWING
Bresenham’s Line Drawing Algorithm

Assumptions:

(i) In Bresenham’s Line Drawing Algorithm (BLDA, for short) we always


increase x by 1, the y-position is determined depending on the nearest of y
value.

(ii) Suppose, the pixel position (xi, yi) is already determined. The next pixel
position to be approximated is either (xi+1,yi) or (xi+1,yi+1).

(iii) Let d1 and d2 be the pixel position of y1 and y1+1 with a y value of actual
line. If d1<d2 the next pixel point is(xi+1,yi) otherwise it is (xi+1,yi+1).

Derivation:
We know that equation of line is y = mx+c.
Now,
yi=m(xi+1)+c
d1=y-y1
d1=m(xi+1)+c-yi ………………..(i)
d2=yi+1-y
d2=yi+1-m(xi+1)-c ………………(ii)
d1-d2=( m(xi+1)+c-yi)-( yi+1-m(xi+1)-c)
consider yi+1=yi+1
d1-d2=2m(xi+1)-2 xi +2c-1
Since m=∆y/∆x
d1-d2 =2∆y/∆x(xi+1)+2c-2yi-1
∆x(d1-d2)=2∆y(xi +1)+2∆xc-2∆x yi -∆x
∆x(d1-d2)=2∆yxi +2∆y+2∆xc-2∆xyi-∆x
consider L.H.S, our decision parameter(Pi) for the ith step ∆x and ∆y will remain
the same throughout.
Pi =2∆y xi -2∆x yi+b …..………..(iii)
Pi+1=2∆y(xi+1)-2∆x yi+1+b ………...…..(iv)
Pi+1 -Pi=2∆y-2∆x(yi+1- yi)

Pi+1 = Pi +2∆y-2∆x(yi+1- yi) …….(v)

Pi+1 = Pi +2∆y-2∆x(y- y1)

Pi+1= Pi+2∆y(Pi<0, d1<d2) ……(vi)

Pi+1 = Pi +2∆y-2∆x(Pi>=0, d1>=d2) ……(vii)

Now,
Pi =2∆yxi-2∆xyi+2∆y+2∆xc-∆x ……….(viii)
Since yi=mxi+c
y1=∆y/∆xx1+c
y1∆x=∆yx1+c∆x
Putting it in (viii)
P1 =2∆yx1-2(∆yx1+c∆x)+2∆y+2∆xc-∆x

P2=P1+2∆y (P1<0)

P2=P1+2∆y-2∆x (P1>=0)

Justification:
Eg. Plot a line between two points (1,1) and (8,5) by using BLDF
Soln
∆x=8-1=7
∆y=5-1=4
P1 = 2*4-7=1
P2 =1+2*4-2*7=-5
P3 =-5+2*4=3
P4 =-3+8-14=-3
P5 =-3+8=5
P6 =5+8-14=-1
P7=-1+8=7

(1,1) 1 1 1
(2,2) 2 2 -5
(3,2) 3 2 3
(4,3) 4 3 -3
(5,3) 5 3 5
(6,4) 6 4 -1
(7,4) 7 4 7
(8,5) 8 5
Y

1 2 3 4 5 6 7 8 9 X

Algorithm:

Step 1 Input the two line endpoints and store the left endpoint in (x1,y1).

Step 2 Load (x1,y1) in the frame buffer, ie, plot the first point.

Step 3 Calculate the constants ∆x and ∆y and P1 =2∆y-∆x if Pi <0 then


next point is (xi +1, y1) otherwise it is (x1+1, y1+1).

Step 4 Continue to increase x by unity, to position xi +1.The coordinate of


yi+1 is either yi or yi+1 depending on whether Pi <0 or Pi >=0.

Step 5 The calculation for each points P depends on the last P (previous).
If Pi <0 then Pi+1 =Pi +2∆y otherwise it is Pi +2∆y+2∆x.Repeat the
procedure in Step 4 untill x coordinate reaches x1.

Properties of a good line:-


(1)Line should appear straight.
(2)Line should terminate accurately.
(3)Line should have constant density.
(4)Line density should be independent of line length and angle.
(4)Line should be drawn rapidly.

Digital Differential Analyzer (DDA) line drawing algorithm:-


It is of two type :
(1) Simple DDA
(2) Symmetrical DDA

(1) Simple DDA :


It is as accurate as its symmetrical counterpart but generates a different sequence of
dots because of its different method of estimating line-length. Logically it is simpler,
except for the need to perform an initial divosion to determine the incrementing
value. The need for division logic makes it less suited to hardware implementation.
Assumptions:-
For the simple DDA we choose a line-length estimate equal to the larger of the
magnitudes of dx and dy.

Algorithm:-

Step 1: Input end-points;store left end point as (x1,y1) and right end point as (x2,y2).
Step 2: Compute dx = x2 - x1 and dy = y2 - y1.
Step 3: Now,compare absolute values of dx and dy.
Put l = max (abs(dx), abs(dy)).
Step 4: Calculate xincrement = dx/l and yincrement = dy/l.
Step 5: Put x = x1, y = y1.
Step 6: Set-pixel(x,y).
Step 7: for k=1 to l
x=x1+xincrement
y=y1+yincrement
Set_pixel(x,y)
End

Example:-
Draw a line between points (0,0) and(6,4).
dx = 6-0 = 6
dy = 4-0 = 4
l = max (abs(6),abs(4)) = 6
xincrement = 6/6 = 1
yincrement = 4/6 = 0.6

Plot X Y
(0,0) 0 0.0
(1,1) 1 0.6
(2,1) 2 1.2
(3,2) 3 1.8
(4,2) 4 2.4
(5,3) 5 3.0
(6,4) 6 3.6

0 1 2 3 4 5 6 7 8 X
(2) Symmetrical DDA :

The DDA generates lines from their differential equations. The equation of the
straight lines is :

dx /dy = ∆y/∆x -(1)

The DDA works on the principle that we simultaneously increment x and y by small
steps proportional to the forst derivatives of x and y. In the case of the straight lines, the
first derimvative are constant and are proportional to ∆x and ∆y. Thus in the ideal case of
an infinite precision display we could generate a line by incrementing x and y by ε∆x and
ε∆y, where ε is some small quantitiy.
In the real world of limited precision display we must generate only addressable
points. This can be done by rounding to the nearest integer after each incremental step,
after rounding we display a dot at the resultant x and y.
An alternative to rounding is the use if arithmetic overflow; x and y are kept in
register that have two parts- integer and fractional. The incrementing values, which are
both less than unity, are repeatedly added to the fractional parts, and whenever the result
overflows, the corresponding integer part is incremented.
The integer parts of the x and y registers are used in plotting the line. This woulod
normally have the effect of truncating rather than rounding, so we initialize the DDA
with the value 0.5 in each of the fractional parts to achieve true rounding.
The appearance of line generated by the DDA depends on the value chosen for ε.
In the case of the symmetrical DDA, we choose ε = 2-n ,

where 2n-1 <= max (|∆x|, |∆y|) < 2n -(2)

In fact ε is the reciprocal of the DDA’s line-length estimate, in this case 2n.

Integer Part Fraction Part Integer Part Fractiion Part

+ +

ε∆x ε∆y
The symmetrical DDA generates accurate lines since displacement of a displayed dot
from the true line is never greater than one half ‘a screen unit. Logically, the symmetrical; DDA
is simple, the use of a negative power of 2 for ε m,eans that the incrementing value can be
determined by shifting the ∆x and ∆y registers rather rhan by a division. Each step in the line is
computed with just two additions.

Assumption
The symmetrical DDA uses a power of 2 as a line estimate, since it simplifies the logic.

Algorithm
Step 1: Input end points,store left point as (x1,y1) and right point as (x2,y2).

Step 2: Calculate dx=x2-x1, dy=y2-y1

Step 3: Solve the following inequality for n:


2n-1<=max(|dx|,|dy|)<2n

Step 4: Calculate ε=2-n

Step 5: Calculate x1`=x1,y1`=y1

Step 6: Setpixel(x1`,y1`)

Step 7: For(k=1 to min(ε.dx,ε.dy),k++)


{
x1`=x1`+ε.dx;
y1`=y1`+ε.dy;
setpixel(x1`,y1`);
}
end

CIRCLE-DRAWING
Bresenham’s circle-drawing Algorithm

Assumption :
Eight-way symmetry is used by reflecting each calculated point around each 45o
axis (reflecting about Y-axis and X-axis). The best approximation of the true circle will
be described by those pixels in the raster that fall the least distance from the true circle. If
points are generated from 90o and 45o, each new point closest to the true circle can be
found by taking the either of two actions:
(1) Move in the x-direction 1 unit
(2) Move in the x-direction 1 unit and move inthe (-) ve Y-direction 1 unit
d1 distance is defined as
d1= yi2 – y2
and d2 = y2 – (yi-1)2
(xi,yi) next point -> (xi+1,yi) or (xi + 1, yi, - 1)
We know that equation of the circle is
x2 + y2 = r2
 y2 = r2 – x2
y2 = r2 – (xi + 1)2 ( because x has to increment)
d1 = yi2 – y2 = yi2 – r2 + (xi + 1)2 -(1)
& d2 = y2 – (yi – 1) = r2-(xi+1)2-(yi-1)2 - (2)
Pi = d1 – d2 = 2(xi+1)2 – 2r2 + 2yi2 – 2 yi + 1 - (3)

Pi+1 = 2(xi + 2)2 - 2r2 + 2yi+12 - 2yi+1 + 1 - (4)

(Because xi+1 = xi +1)


Pi+1 – Pi = 4 xi + 6 + 2 (yi+12 – yi2) – 2 (yi+1 – yi)
If d1 <d2 i.e. P1 <0
Pi+1 = Pi +4 xi+6 + 2 (yi2-yi2)-2(yi – yi)

Pi+1 = Pi + 4 xi + 6 -(5)

Ifd1 >=d2 i.e P1 >=0


Pi+1 = Pi+4 xi + 6 + 2 (-2yi) – 2 (-1)

Pi+1 = Pi + 4 (xi – yi) + 10 - (6)

Put x = 0, y=r in equation (4),

P1 = 3-2r -> decision parameter

Example – Generate a circle with centre (0,0) and radius r

Plot x y P=3-2r
(0,3) 0 3 -3
(1,3) 1 3 7
(2,2) 2 2 17

(0,3) => (0,3), (3,0), (0,-3), (-3,0),


(1, 3) => (1,3), (3,1), (-1,3), (3,-1), (1,-3), (-3,1), (-1,-3), (-3,-1)
(2,2) => (2,2), (-2,2), (2,-2), (-2,-2)
Y
x=y

0 1 2 3 4 X
Mid-point Circle Algorithm:

Assumption :
To apply the midpoint method, we define a circle function:
fcircle (x,y) = x2 + y2 - r2
Any point (x,y) on the boundary of the circle with radius r satisfies the
equation fcircle (x,y) = 0. If the point is in the interior of the circle, the circle function is
negative. And if the point is outside the circle, the circle function is positive. To
summarize, the relative position of any point (x,y) can be determined by checking the
sing of the circle function.

< 0, if (x,y) is inside the circle boundary


fcircle (x,y) = 0, if (x,y) is on the circle boundary
> 0, if (x,y) is outside the circle boundary
The circle-function are performed for the midpositions between pixels
near the circle path at each sampling step. Thus, the circle function is the decision
parameter in the midpoint algorithm.
Initial value of decisions parameter
Po = 5/4 – r
If the radius r is specified as an integer, we can simply round P0 to
P0 = 1 – r (for r an integer)

since all increments are integers.


If Pk < 0, the next point along the circle centered on (0,0) is (Xk+1, Yk) and,
Pk+1 = Pk + 2Xk+1 + 1
Otherwise, the next point along the circle is (Xk+1, Yk -1) and
Pk+1 = Pk + 2Xk+1 + 1 – 2Yk+1
where 2Xk+1 = 2Xk + 2 and 2Yk+1 = 2Yk-2
Algorithm :
1. Input radium r and circle centre (xc, yc) and obtain the first point on the
circumference of a circle centered on the origin as
(xo, yo) = (0, r)
2. Calculate the initial value of the decision parameter as
P0 = 5/4 –r
3. At each Xk position, starting at K = 0, perform the following test : If Pk < 0
the next point along the circle centered on (0,0) is (Xk+1, Yk) and Pk+1 =
Pk + 2Xk+1 + 1
Otherwise, the next point along the circle is (Xk+1, Yk -1) and
Pk+1 = Pk + 2Xk+1 + 1 – 2Yk+1
where 2Xk+1 = 2Xk + 2 and 2Yk+1 = 2Yk-2
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (x, y) onto the circular path centered
on (xc, yc) and plot the coordinate values:
x = x + xc, y = y + yc
6. Repeat steps 3 through 5 until x > y
EXAMPLE:
Given a circle radius r=10, we demonstrate the mid-point circle algorithm
by determining positions along the circle octant in the first quadrant from x=0 to x=y.
The initial value of the decision parameter is
P0 = 1 – r = -9
For the circle centered on the coordinate origin, the initial point is (x0, y0)
= (0,10), and initial increment terms for calculating the decision parameters are
2X0 = 0, 2Y0 = 20
Successive decision parameters values and positions along the circle path
are calculated using the midpoint method as:

K Pk (Xk+1, Yk+1) 2Xk+1 2Yk+1

0 -9 (1,10) 2 20
1 -6 (2,10) 4 20
2 -1 (3,10) 6 20
3 6 (4,9) 8 18
4 -3 (5,9) 10 18
5 8 (6,8) 12 16
6 5 (7,7) 14 14

Y X=Y

10

9
8
7

6
5
4

3
2

1
0
0 1 2 3 4 5 6 7 8 9 10 X

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy