2. CST 304
Computer Graphics and Image Processing
Syllabus
Module – 1 (Basics of Computer graphics and Algorithms)
Basics of Computer Graphics and its applications. Video Display
devices- Refresh Cathode Ray Tubes, Random Scan Displays and
systems, Raster scan displays and systems. Line drawing algorithms-
DDA, Bresenham’s algorithm. Circle drawing algorithms- Midpoint
Circle generation algorithm, Bresenham’s algorithm.
3. CST 304
Computer Graphics and Image Processing
Module – 2 (Filled Area Primitives and transformations)
Filled Area Primitives- Scan line polygon filling, Boundary filling and
flood filling. Two dimensional transformations-Translation, Rotation,
Scaling, Reflection and Shearing, Composite transformations, Matrix
representations and homogeneous coordinates. Basic 3D
transformations.
4. CST 304
Computer Graphics and Image Processing
Module - 3 (Clipping and Projections)
Window to viewport transformation. Cohen Sutherland Line clipping
algorithm. Sutherland Hodgeman Polygon clipping algorithm. Three
dimensional viewing pipeline. Projections- Parallel and Perspective
projections. Visible surface detection algorithms- Depth buffer
algorithm, Scan line algorithm.
5. CST 304
Computer Graphics and Image Processing
Module - 4 (Fundamentals of Digital Image Processing)
Introduction to Image processing and applications. Image as 2D data.
Fundamentalstepsinimageprocessing.Components of
Image representationinGrayscale,Binaryand Colour images.
image
processing system. Coordinate conventions. Sampling and quantization.
Spatial and Gray Level Resolution. Basic relationship between pixels–
neighbourhood, adjacency, connectivity. Fundamentals of spatial
domain-convolution operation.
6. CST 304
Computer Graphics and Image Processing
Module - 5 (Image Enhancement in Spatial Domain and Image
Segmentation)
Basic gray level transformation functions - Log transformations, Power-
Law transformations, Contrast stretching. Histogram equalization.
Basics of spatial filtering - Smoothing spatial filter- Linear and nonlinear
filters, and Sharpening spatial filters-Gradient and Laplacian.
Fundamentals of Image Segmentation. Thresholding - Basics of
Intensity thresholding and Global Thresholding. Region based Approach
- Region Growing, Region Splitting and Merging. Edge Detection - Edge
Operators- Sobel and Prewitt.
7. Module 1 - Basics of Computer Graphics and
Algorithms
Basics of Computer Graphics and its applications. Video Display
devices- Refresh Cathode Ray Tubes, Random Scan Displays and
systems, Raster scan displays and systems. Line drawing algorithms-
DDA, Bresenham’s algorithm. Circle drawing algorithms- Midpoint
Circle generation algorithm, Bresenham’s algorithm.
8. Basics of Computer Graphics
What is Computer Graphics?
• Computer Graphics includes all aspects of creating or synthesizing images
using a computer.
• Creation of images, Storage, Modelling of geometric objects and
Projecting 3D models onto 2D plane (Rendering) are part of Computer
Graphics.
• Displaying these images on computer screen or other hardcopy output
devices like printers, plotters etc. is also part of Computer Graphics.
9. Basics of Computer Graphics
Computer Graphics Vs Image Processing
• In Computer Graphics, computer is used to create a picture.
• In Image Processing, computer is used to modify or interpret existing
pictures.
10. Basics of Computer Graphics
Types of Computer Graphics – broadly divided into two:
• Non interactive (Passive) Computer Graphics – observer has no
control over the image. Example: Titles shown on TV
• Interactive Computer Graphics – involves two way communication
between computer and user. Example: Video games
11. Applications of Computer Graphics
• Computer Aided Design (CAD)
• Presentation Graphics
• Computer Art
• Entertainment (Animation, Games etc.)
• Education and Training
• Visualization (Scientific and Business)
• Image Processing
• Graphical User Interfaces
13. Applications of Computer Graphics
Computer Aided Design
Animations – real time animations using wire frame displays are helpful
in many industries
Animations in Virtual Reality environment
Architectural designs and visualization – 3D rendering and
walkthroughs
15. LEARN G ROW .E X C E L Dr
. Santízesíz P Matíze
SAINTGITS
Examples of presentation
graphics
30 Bananas Z9 CUCLlMbef5
30
20 Oranges
20
10 10 'Omat
Stcmrlrii ‹:l Line Cfini I Lin S n
31. Applications of Computer Graphics
• Computer Aided Design (CAD)
• Presentation Graphics
• Computer Art
• Entertainment (Animation, Games etc.)
• Education and Training
• Visualization (Scientific and Business)
• Image Processing
• Graphical User Interfaces
35. Video Display Devices
– Refresh Cathode Ray Tube
How are spots of light produced on the CRT Screen?
• Spots of light are produced on the screen by the transfer of the
CRT beam energy to the phosphor.
• Part of the beam energy (kinetic) is converted by friction into
heat energyandtheremaindercauseselectrons in the
phosphor atoms to move up to higher quantum energy levels.
• After ashorttime,theexcitedphosphorelectrons
begin
dropping back to their stable ground state, giving up their
extra energy as small amounts of light energy.
• What we see on the screen is the combined effect of all the
electron light emissions and these spots of light quickly fading
as the phosphor electrons return to ground energy level.
Hence refreshing is done to retain the image.
36. Video Display Devices
– Refresh Cathode Ray Tube
Cutaway rendering of a color
CRT:
1.Three electron emitters
(for red, green, and blue
phosphor dots)
2. Electron beams
3. Focusing coils
4. Deflection coils
5. Connection for final
anodes
6.Mask for separating
beams for red, green, and b
lue part of the displayed
image
7.Phosphor layer
(screen)with red, green, and
blue zones
37. Video Display Devices
– Refresh Cathode Ray Tube
The rear of a 14-inch color cathode-ray tube showing its deflection coils
and electron guns
38. Video Display Devices
Some terms connected with the display screen:
• Persistence
Persistence is defined as the time it takes the emitted
light from the screen to decay to one tenth of its original
intensity.
• Resolution
The maximum number of points that can be displayed
without overlap on a CRT is referred to as the resolution.
• Aspect Ratio
This number gives the ratio of horizontal points to
vertical points (sometimes - vertical points to horizontal
points).
39. Video Display Devices
Here’s a breakdown of the different aspect ratios:
• 16:9 aspect ratio: (modern standard) 1366 x 768,
1600 x 900, 1920 × 1080, 3840 × 2160, 2560 × 1440
• 4:3 aspect ratio: (old standard) 1400 × 1050, 1440 ×
1080, 1920 × 1440
• 21:9 aspect ratio: (ultrawide) 2560 × 1080, 3440 ×
1440
• 32:9 aspect ratio: (superwide) 3840 × 1080
52. Line Drawing algorithms- DDA
m = (yk+1 – yk) /( xk+1 –xk)
Here we increment x by 1. So xk+1 -xk = 1
Therefore, m = (yk+1 – yk)/1
Yk+1 = yk + m
Here we increment y by 1 . So yk+1 – yk = 1
Hence: m = 1 / ( xk+1 – xk )
(xk+1 – xk ) = 1/m
xk+1 = xk + 1/m
53. Line Drawing algorithms - DDA
Xinc = dx/steps Yinc = dy/steps. When slope m<1, steps = dx and
Xinc = dx/dx =1. We need to increment x by 1 and calculate
corresponding y.
When slope m>1, steps =dy and Yinc = dy/steps =1 and
Xinc = dx/steps = dx/dy = 1/m We need to increment y by 1
and calculate corresponding x value.
when m>1, y
k+1 = yk + 1 xk+1
= xk + 1/m
when m<1,
xk+1 = xk + 1
yk+1 = yk + m
60. LEARN G ROW .E X C E L Dr
. Santízesíz P Matíze
BRINTBITS
s ^¥'-It.H.G
CEL
!2
£16URE 3-BA mctiori of a
display screen where a
straight-line segment is to
be ploaed, starting &mthe
. Specified
—
FIGURE 2-9A gchon
of a disphy screen where s
I1ne se//nect
is
61. The Problem (cont…)
• What happens when we try to draw this on a pixel
based display?
How do we choose which pixels to turn
62. • In Bresenham’s line drawing algorithm the
incremental integer calculations are used to scan
convert the lines, that can be adapted to display
circles and the other curves as well.
?
??
?
63. • .The next sample positions can be plotted either at (3,2) or
(3,3) ?
?
?
(2,2) ?(3,2)
(3,3)
?
66. SRINTGITS
To illustraie Brewnham's approach, we first consider the scan«onversion
prŒCss Éor 1inŒ vilži posíŃ>’e slgpe les« than
.0. 7ixelgo«ÌtÌasss aÎong a line
path are Œen determined by sampÍing at unił s irlRrvals. Starting from the le8
endpoint (at, p) of a @ven line, we sRp to oach succmsive <olumn țr position) and plot the
pixel whnse scan-line ș valueis c
l
o
s
e
s
t to t
h
e hne pnh. Figue %
1
0 denionsłratm the
kth Sh«p č‹ this pu›cess. Æsumïng v
•
e ha‹'e d 't
e
rmiDe
dt
h
a
t ltte pixel at (z•t,
¡ș} is to be displeșed, we next need to decide which pixel to plot
in column x¡_; = Sp 4- 1. Our choices are the pixels ał pœitìons (xt + 1, q) and
-'i•i -› 'i -' '‹ . ‹
r›r»UfiŁ :t1‹ i
A sc,ti„„ of the
6€reõn shoTt•ing a pixel in
cnlumn xr on xan line g-
that G
s to be pIottød along
67. For lines with positive slope m<1
The pixel positions on line can be identified by doing sampling along x
axis at unit intervals.
The process of sampling begins from the pixel position (X0,Y0) and
proceeds by plotting the pixels whose ‘Y’ value is nearest to the line
path.
If the pixel to be displayed occurs at a position (Xk, Yk) then the next
pixel is either at (Xk +1 ,Yk) or (Xk +1,Yk+1) i.e, (3,2) or (3,3)
The ‘Y’ coordinate at the pixel position Xk+1 can be obtained from
Y=m(Xk+1)+b. . . . . . . . . . …….eq 1
68. Bresenham’s - for lines with positive
slope m<1
• the separation between (Xk+1,Yk) and (Xk+1,Y) is d1 and the
separation between (Xk+1,Y) and (Xk+1, Yk+1) is d2 then
• d1 = y – ykand
• d2 = (Yk+1) – Y
.
(Xk, yk+1) (Xk+1, yk+1)
d2
(xk+1,y)
P0
(Xk, yk)
d1
(Xk+1,yk)
69. Bresenham’s - for lines with positive
slope m<1
. . . . . . . …….eqn 1
y=m(Xk+1)+b d1=y
– yk ………..eqn 2
d1=m(xk+1)+b – Y
k
( from eqn (1)…..( 2)
And d2= (Yk+1) – Y
=(YK+1) – [m(Xk+1)+b]
=(YK+1) – m(Xk+1) – b…….(3)
The difference is given as
d1-d2 =
= m(Xk+1)+b-Yk
-[(Yk+1)-m(Xk+1)-
b]
70. Contd..
A decision parameter Pk can be obtained by substituting m= dy/dx in equation 4
d1 – d2 = 2m(Xk+1)-2Yk+2b – 1
= 2 dy/dx (Xk+1) – 2Yk + 2b – 1
= 2 dy(Xk+1)-2 dx.Yk + 2b.dx -
dx dx
dx(d1-d2) = 2 dy(Xk+1)-2 dx.Yk + 2b.dx - dx
= 2 dyXk+2 dy-2 dx.Yk + 2b.dx -dx
= 2 dyXk- 2 dx.Yk + c
Where, dx(d1-d2) = Pk andc= 2 dy+ dx(2b-1)
Pk = 2 dyXk- 2 dx.Yk + c . . . . . . . . . . . . . . . . . . . … …(5 )
The value of c is constant and is independent of the pixel position. It can be deleted in the recursive
calculations, of for Pk
if d1 < d2 then, Pk is negative (i.e, Yk is nearer to the line path than Yk+1)
If Pk is –ve, a lower pixel (Yk)is plotted else, an upper pixel (Yk+1)is plotted.
At k+1 step, the value of Pk is given as
PK+1 = 2 dyXk+1- 2 dx.Yk+1 + c …………………………………..(6 ) (from 5)
71. • Eq 6 – eq 5
• Pk+1 – Pk = (2 dyXk+1- 2 dx.Yk+1 + c ) - (2 dyXk+2 dx.Yk + c)
• = 2dy(Xk+1-Xk ) – 2 dx(Yk+1 – Yk ) ………….(7)
• Since Xk+1 = Xk +1The eqn 7 becomes
• Pk+1 – Pk = 2dy(Xk +1-Xk ) – 2 dx(Yk+1 – Yk )
• = 2dy - 2 dx(Yk+1 – Yk )
• Pk+1 = Pk + 2dy - 2 dx(Yk+1 – Yk )………………..( 8)
• Where (Yk+1 – Yk) is either 0 or 1 based on the sign of Pk (if Pk is –ve, Yk is not incremented: Yk+1 = Yk)
• The starting parameter P0 at the pixel position (X0,Y0) is given as
• P0 = 2dy – dx………………………(9)
72. y=mx+c is the eq of line
In col 2 the line is passing through x0+1 so
the y value is given by
y=m(x0+1)+c(green dot)
Now we need to find out the values of d1
and d2
d1= y-y0
d2=(y0+1)-y
d1=m(x0
+1) – y0
and d2= (y0
+1) - m(x0
+1)
d1-d2=[mx
0+m – y0] -
[(y0+1) - mx
0-m]
=mx0
+m –
y0 - y0
P0= 2∆y - ∆x
Col 1 Col 2
∆x(d1-d2) = 2∆y - ∆x
(X0, y0+1) (X0+1, y0+1)
d2
(x0+1,y)
P0
(X0, y0)
d1
(X0+1,y0)
73. Bresenham’s algorithm
• Step 1: Enter the 2 end points for a line and store the
left end point in (X0,Y0).
• Step 2: Plot the first point by loading (X0,Y0) in the
frame buffer.
• Setp 3: determine the initial value of the decision parameter
by calculating the constants dx, dy, 2dy and 2dy-2dx as
• P0 = 2dy –dx
• Step 4: for each Xk, conduct the following test, starting from k=
0
• If Pk <0, then the next point to be plotted is at (Xk+1, Yk) and
• Pk+1 = Pk + 2dy
• Note: Pk+1 = Pk + 2dy - 2 dx(Yk+1 – Yk ) ….here y values remain the same. Hence Yk+1 – Yk = 0
• Else, the next point is (Xk+1, Yk+1) and
• P = P + 2dy –2dx(step 3)
74. Example
• Let the given end points for the line be (30,20)and (40, 28)
• m = dy = y2 – y1= 28 – 20= 8
dx x2 – x140 – 30 = 10
• m =0.8
dy = 8anddx = 10
• The initial decision parameter P0
is
• P0 = 2dy – dx= 2(8) – 10 = 16 –
10= 6
P0 = 6
• The constants 2dy and 2dy-2dx
are
• 2dy = 2(8) = 16
2dy = 16
2dy-2dx = 2(8)- 2(10) =16 – 20 = -4
2dy – 2dx = - 4
75. The starting point (x0, y0)=(30,20) and the successive
pixel positions are given in the following table
dy = 8 and dx = 10 If Pk is +ve, Pk+1 = Pk + 2dy –2dx = Pk – 4 If Pk is –ve, Pk+1 = Pk+2dy = Pk+16
K Pk
(Xk+1, Yk+1)
0 6 (31,21)
1 2 (32,22
2 -2 33,22
3 14 34,23
4 10 35,24
5 6 36,25
6 2 37,26
7 -2 38,26
8 14 39,27
9 10 40,28
77. • In bresenham’s algorithm, if the positive slope of a line is greater than 1, the
roles of x and y are interchanged.
• For positive slope lines:
1. If the initial position of a line is the right end point, then both x and y are
decremented as we move from right to left.
2. If d1 = d2 then select the upper or the lower candidate pixel.
• For negative slope lines:
• One coordinate increases and the other coordinate decreases.
• Special cases:
• the vertical lines dx = 0, horizontal lines dy = 0 and diagonal lines |dx| =
|dy| can be directly loaded into the frame buffer.
78. Void LineBres( int x1, int y1, int x2, int y2)
{
int dx =abs(x2-x1), dy= abs(y2-y1)
int p=2* dy- dx ;
int x, y, Xend; // Xend is similar to steps in DDA
// Determine which point to start and which as
end If(x1>x2)
{
x=x2;y=y2;Xend=x1;
}
else
{
x=x1;y=y1;Xend=x2;
}
setPixel( x, y );
While( x < Xend)
{
x++;
if( p < 0)
p=p+2dy;
else
{
y++;
p=p+2dy-2
dx;
}
setPixel(x,y);
}// End While
}//End LineBres
80. Circle Drawing Algorithms
• Circle – As et of all points in a plane which are at a
fixed distance from a fixed point
• Circle Equation:
(Polynomial) -
When center is at (xc, yc) => (x-xc)2 + (y-yc)2= r2
(0,0)=> x2 + y2 = r2
Trigonometric (Polar coordinate) –
x = r cosӨ and y = r sinӨ
82. Circle Drawing Algorithms
Polynomial Method of Circle representation
In this method, Circle is represented by a Polynomial Equation: x2 + y2 = r2
Here, this equation can be used to find ‘y’ coordinates for the known ‘x’ coordinates
– ‘r’ is also known.
The scan converting circle using this method is
achieved by stepping ‘x’ from 0 to r/√2 and each ‘y’
coordinate value Is found by evaluating √(r2-x2) for
each step of ‘x’.
This will generate 1/8 portion (900 to 450) of the
circle. Remaining for other octants are generated
the circle symmetry principle.
84. Circle Drawing Algorithms
• Trigonometric / Polar CoordinateMethod:
x = r cosӨ and y = r sinӨ
where Ө is the current angle and x and y are the respective x and y
coordinates.
The scan convertingcircleusingPolar
coordinate method is achieved by
stepping Ө from 0 to 450and
calculating each x and y value. Using 1/8
symmetry concept remaining points in
other octants are found out.
This method is also quite inefficient and
time consuming because of the
repeated computation of sinӨ and
cosӨ.
85. Bresenham’s Circle Drawing Algorithm
This is an efficient circle drawing algorithm because it avoids
square root and trigonometric calculations. It involves only in
teger operations. 1/8th of a circle is plotted from 90o to 45o
where x moves in the positive direction and y in the negative
direction. 8 way symmetry of the circle is considered to
generate the remaining points.
93. LEARN G ROW .E X C E L Dr
. Santízesíz P Matíze
BRIMTBIT
S
B
re
s
e
n
h
a
m
'
s circie drawing
algorithm
Algorithm:
ten-I: Input radius r and circle K
M
2Xc.Jq ) obtained the first point
(Xo, Yo) — (0.r)
Sitep-2: QIE$lnte the init»l value of decision p»ameter es
P -3 -Zr
.Step-3: At each Xs position starting at k = 0, peiTonn, the following test:
If Pz < 0, the next point is (Xe + 1, Yx)
Px+i = Pz + 4Xz + 6
otherwise the next point is (Nz + 1. 3"x — I )
as., =, • qx›—,) • io
Deteriiiiiie the symmetry points in other seven octant
fep—I:
?itep-fi: Move each pixel position (?£. Y) into circular pnth
.Uterv-Ii:Repeat step 3 to 5 until XY.
97. Mid-Point Circle Algorithm
• In the midpoint circle drawing algorithm, the midpoint
between two pixels along the circle path is first foun
d out.
• Using a decision variable, it is then checked whether
the midpoint is inside or outside the circle path. If the
midpoint is inside, the outside pixel is chosen and if it
is outside, the inside pixel is chosen.
• Circle is plotted from 90 to 45 degrees and ‘x’ moves in
the positive direction, while ‘y’ moves in the negative
direction.
• Points are identified for one octet and the remaining
points are found out using 8 way symmetry of the
circle.
105. Mid-Point Circle Algorithm
• Calculate the points of a circle with radius 7 and
center at (10,10) using midpoint circle
algorithm. (x0, y0) =(0,r) = (0,7)
center (xc,yc) = (10,10)
d0 = 1-r = 1-7 = -6
k (xk, yk) dk (xk+1 +xc, yk+1 +yc)
0 (x0,y0)=(0,7) d0 = -6 (1,7) => (11,17)
1 (x1,y1)=(1,7) d1 = d0+2x0+3 = -6+2x0+3 = -3 (2,7) => (12,17)
2 (x2,y2)=(2,7) d2 = d1+2x1+3 = -3+2x1+3 = 2 (3,6) => (13,16)
3 (x3,y3)=(3,6) d3 = d2+2(x2-y2)+5 = 2+2(-5)+5 = -3 (4,6) => (14,16)
4 (x4,y4)=(4,6) d4 = d3+2x3+3 = -3+2x3+3 = 6 (5,5) => (15,15)
The points in this octet (90o to 45o) are (10,17), (11,17), (12,17), (13,16), (14,16), (15,15). At 45o,
x=y and we stop here. (We can stop when ‘y’ gets equal or less than x – or continue while y >= x)