Understanding Computer Graphics Basics
Understanding Computer Graphics Basics
The term ‘Computer Graphics’ was coined by Verne Hudson and William Fetter from
Boeing who were pioneers in the field.
Computer graphics is a sub- field of computer science which studies methods for
digitally synthesizing and manipulating visual content.
Computer Graphics can be used in UI design, rendering, geometric objects, animation,
and many more. There are several tools used for the implementation of Computer
Graphics. The basic is the <graphics.h> header file in Turbo- C, Unity for advanced and
even OpenGL can be used for its Implementation.
Types of Computer Graphics
Raster Graphics: In raster, graphics pixels are used for an image to be drawn.
It is also known as a bitmap image in which a sequence of images is into
smaller pixels. Basically, a bitmap indicates a large number of pixels together.
Vector Graphics: In vector graphics, mathematical formulae are used to draw
different types of shapes, lines, objects, and so on.
Once the electron heats the phosphorus, they light up, and they are projected on a
screen. The color you view on the screen is produced by a blend of red, blue and
green light.
Components of CRT:
1. Electron Gun: Electron gun consisting of a series of elements, primarily a heating
filament (heater) and a cathode. The electron gun creates a source of electrons
which are focused into a narrow beam directed at the face of the CRT.
3. Focusing system: It is used to create a clear picture by focusing the electrons into
a narrow beam.
4. Defl ection Yoke: It is used to control the direction of the electron beam. It creates
an electric or magnetic field which will bend the electron beam as it passes through
the area. In a conventional CRT, the yoke is linked to a sweep or scan generator. The
defl ection yoke which is connected to the sweep generator creates a fl uctuating
electric or magnetic potential.
5. Phosphorus- coated screen: The inside front surface of every CRT is coated with
phosphors. Phosphors glow when a high- energy electron beam hits them.
Phosphorescence is the term used to characterize the light given off by a phosphor
after it has been exposed to an electron beam.
Random Scan System uses an electron beam which operates like a pencil to create a
line image on the CRT screen. The picture is constructed out of a sequence of
straight- line segments. Each line segment is drawn on the screen by directing the
beam to move from one point on the screen to the next, where its x & y coordinates
define each point. After drawing the picture. The system cycles back to the first line
and design all the lines of the image 30 to 60 time each second. The process is
shown in fig:
Random- scan monitors are also known as vector displays or stroke- writing displays
or calligraphic displays.
Advantages:
1. A CRT has the electron beam directed only to the parts of the screen where
an image is to be drawn.
3. High Resolution
Disadvantages:
Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions are
called picture elements or pixels. Beam refreshing is of two types. First is horizontal
retracing and second is vertical retracing. When the beam starts from the top left
corner and reaches the bottom right scale, it will again return to the top left side
called at vertical retrace. Then it will again more horizontally from top to bottom call
as horizontal retracing shown in fig:
1. Interlaced Scanning
In Interlaced scanning, each horizontal line of the screen is traced from top to
bottom. Due to which fading of display of object may occur. This problem can be
solved by Non- Interlaced scanning. In this first of all odd numbered lines are traced
or visited by an electron beam, then in the next circle, even number of lines are
located.
For non- interlaced display refresh rate of 30 frames per second used. But it gives
fl ickers. For interlaced display refresh rate of 60 frames per second is used.
Advantages:
1. Realistic image
Disadvantages:
1. Low Resolution
2. Expensive
5. Refresh rate depends or resolution 5. Refresh rate does not depend on the
picture.
7. Beam Penetration technology come under 7. Shadow mark technology came under
it. this.
Direct View Storage Tube (DVST) resembles CRT as it uses electron gun to draw
picture and phosphor coated screen to display it. The phosphor used in this is of high
persistence. DVST does not use refresh buffer or frame buffer to store picture
definition. Picture definition is stored in inside CRT in form positive charged
distribution. Because of this reason DVST is knows as Storage Type CRT. In DVST no
refreshing is required as result picture drawn on DVST will be seen for several
minutes before fading.
Advantage:
1. No refreshing is needed.
2. High Resolution
Disadvantage:
Input Devices
The Input Devices are the hardware that is used to transfer transfers input to the
computer. The data can be in the form of text, graphics, sound, and text. Output
device display data from the memory of the computer. Output can be text, numeric
data, line, polygon, and other objects.
To construct various images and graphics in interactive manner, there are different
methods which are built into various graphics packages. These packages contains
various options which help user to enter information of coordinate by using stroke
devices or various locators. These coordinates helps in creating boundaries for
various objects which user is going to drawn.
Positioning Techniques :
It very basic technique of graphical input. It is also known as locating.
With the help of input device, user indicates position on the screen. To display
object this position marks location. Example: input position can be used to insert
symbol to specify endpoint of line.
The process of positioning involves two steps, in first step user have to move
cursor to desired spot on screen and in second step user inform computer by
pressing key or button.
The positioning is very often used in geometric modeling applications, where
if user wants to define new element of model or to change position of already
existing model.
Popular examples of GUIs are Microsoft Windows, macOS, Android and Apple's iOS.
GUIs are also how we interact with the internet through web browsers like Google
Chrome, Microsoft Edge and Firefox.
Image representation
Image representation is a vast and fundamental concept in computer science
that enables the interpretation and manipulation of images in computing systems.
The way an image is represented can impact the result of tasks in fields such as
computer vision, machine learning, and digital graphics.
An image can be represented in various forms. Most of the time, it refers to the way
that brings information, such as color is coded digitally, and how the image is stored,
i.e., how an image file is structured.
Several open standards were recommended to create, manipulate, store, and
exchange digital images. The rules described the format of image files, the
algorithms of image encoding, the form of additional information often named as
metadata.
A digital image is the composition of individual pixels or picture elements. The pixels
are arranged in the form of row and column to form a picture area. The number of
pixels in an image is a function of the size of the image and number of pixels per unit
length (e.g., inch) in horizontal as well as vertical direction.
Image Processing
It is a method to implement some operations on an image. It is also used to get an
enhanced image or to access some useful information from an image. It is a type of
processing in which the input is an image, and output may be the image or
characteristics/features correlated with that image.
For example- photographs, frames of video.
Most image processing techniques consider the image as a two- dimensional and
applying standard signal- processing technique on it.
Pixel: “Pixel is the smallest unit of a picture displayed on the computer screen.”
A pixel includes its own:-
Intensity
Name or Address
The size of the image is defined as the total number of pixels in the horizontal
direction times the total number of pixels in the vertical direction (512 x 512,640 x
480, or 1024 x 768).
The ratio of an image’s width to its height, we can measure it in unit length or
number of pixels, is known as the aspect ratio of the image.
For example- A 2 x 2inch image and a 512 x 512 image have an aspect ratio of 1/1,
whereas a 6 x 4inch image and a 1024 x 768 image have an aspect ratio of 4/3.
Resolution: It is the number of separate pixels display on a screen expressed in
terms of pixels on the horizontal axis and vertical axis.
The sharpness of the picture on display depends on the resolution and the size of the
monitor.
“The number of pixels per unit is called the resolution of the image.”
It also includes-
Image Resolution: “The distance between two pixels.”
Screen Resolution: “The number of horizontal and vertical pixels displayed on
the screen is called Screen Resolution.”
For Example- 640 x 480, 1024 x 768 (Horizontal x Vertical)
Aspect Ratio: “The ratio of image’s width to its height is known as the aspect ratio of
an image.” The height and width of an image are measured in length or number of
pixels.
For Example: If a graphics has an aspect ratio of 2:1, it means the width is twice large
to height.
It includes-
Frame aspect ratio: Horizontal /Vertical Size
Pixel aspect ratio: Width of Pixel/Height of Pixel
Applications of Image Processing
Some application areas of Image Processing are as follow:
1. Computerized Photography
6. Remote sensing
7. Industrial application
DDA Algorithm
DDA stands for Digital Differential Analyzer. It is an incremental method of scan
conversion of line. In this method calculation is performed at each step but by using
results of previous steps.
Step1: Start
Step2: Declare x1,y1,x2 ,y2 ,dx,dy,x,y as integer variables.
Step3: Enter value of x1,y1,x2 ,y2 .
Step4: Calculate dx = x2 - x1
Step5: Calculate dy = y2 - y1
Step6: If ABS (dx) > ABS (dy)
Then step = abs (dx)
Else
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Step8: Set pixel (x, y)
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
Step10: Repeat step 9 until x = x2
Step11: End
Advantage:
1. It is a faster method than method of using direct use of line equation.
2. This method does not use multiplication theorem.
3. It allows us to detect the change in the value of x and y ,so plotting of same
point twice is not possible.
4. This method gives overfl ow indication when a point is repositioned.
5. It is an easy method because each step involves just two additions.
Disadvantage:
1. It involves fl oating point additions rounding off is done. Accumulations of
round off error cause accumulation of error.
2. Rounding off operations and fl oating point operations consumes a lot of time.
3. It is more suitable for generating line using the software. But it is less suited
for hardware implementation.
Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How many points
will needed to generate such line?
Solution: P1 (2,3) P11 (6,15)
x1=2
y1=3
x2 = 6
y2 =15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m=
Example: Starting and Ending position of the line are (1, 1) and (8, 5). Find
intermediate points.
Solution: x1=1
y1=1
x2 =8
y2 =5
dx= x2 - x1=8- 1=7
dy=y2 - y1=5- 1=4
I1=2* ∆y=2*4=8
I2 =2*(∆y- ∆x)=2*(4- 7)=- 6
d = I1- ∆x=8- 7=1
x Y d=d+I1 or I2
1 1 d+I2 =1+(- 6)=- 5
2 2 d+I1=- 5+8=3
3 2 d+I2 =3+(- 6)=- 3
4 3 d+I1=- 3+8=5
5 3 d+I2 =5+(- 6)=- 1
6 4 d+I1=- 1+8=7
7 4 d+I2 =7+(- 6)=1
8 5
Mid- Point Line Drawing Algorithm
The Mid- point Subdivision algorithm is the extension of the Cyrus- Beck algorithm.
The Mid- Point line plotting algorithm was introduced by “Pitway and Van Aken.” It is
an incremental line drawing algorithm. In this algorithm, we perform incremental
calculations. The calculations are based on the previous step to find the value of the
next point. We perform the same process for each step. By using the mid- point
subdivision algorithm, we can draw a line with close approximation between two
points. The mid- point subdivision line drawing algorithm subdivides the line at its
midpoints continuously.
The Mid- point Subdivision algorithm helps to compute or calculate the visible areas
of lines that appear in the window. This line plotting algorithm follows the bisection
method to divide the line into equal partitions.
Algorithm:
Given-
Step- 01:
∆X = Xn – X0
∆Y =Yn – Y0
Step- 02:
D initial = 2∆Y – ∆X
∆D = 2(∆Y – ∆X)
Step- 03:
For each D new value, follow the above cases to find the next coordinates.
Problem- 01:
Calculate the points between the starting coordinates (20, 10) and ending
coordinates (30, 18).
Solution-
Given-
Step- 01:
∆X = Xn – X0 = 30 – 20 = 10
∆Y =Yn – Y0 = 18 – 10 = 8
Step- 02:
D initial = 2∆Y – ∆X = 2 x 8 – 10 = 6
∆D = 2(∆Y – ∆X) = 2 x (8 – 10) = - 4
Step- 03:
As D initial >= 0, so case- 02 is satisfied.
Thus,
Xk+1 = Xk + 1= 20 + 1= 21
Yk+1 = Yk + 1= 10 + 1= 11
D new = D initial + ∆D = 6 + (- 4) = 2
20 10
6 2 21 11
2 -2 22 12
-2 14 23 12
14 10 24 13
10 6 25 14
6 2 26 15
2 -2 27 16
-2 14 28 16
14 10 29 17
10 30 18
Now we draw the line in below graph using above set of points:
Advantages of Mid- point Subdivision Line Drawing Algorithm
It is very easy to implement.
It is a less time- consuming algorithm.
This algorithm uses basic arithmetic operations.
It only requires integer data.
The drawn line is smooth than other line drawing algorithms.
Disadvantages of Mid- point Subdivision Algorithm
Sometimes this algorithm is not suitable due to critical images and graphics.
The points have less accuracy. There are improvements needed.
Procedure-
Given-
Centre point of Circle = (X0 , Y0 )
Radius of Circle = R
The points generation using Mid Point Circle Drawing Algorithm involves the
following steps-
Step- 01:
Assign the starting point coordinates (X0 , Y0 ) as-
X0 = 0
Y0 = R
Step- 02:
Calculate the value of initial decision parameter P0 as-
P0 = 1– R
Step- 03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter
Pk.
Step- 04:
If the given centre point (X0 , Y0 ) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0
Here, (Xc, Yc) denotes the current value of X and Y coordinates.
Step- 05:
Keep repeating Step- 03 and Step- 04 until Xplot >= Yplot.
Step- 06:
To find the points for other seven octants, follow the eight symmetry property of
circle.
Problem:
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to
form a circle.
Solution-
Given-
X0 = 0
Y0 = R = 10
Step- 02:
P0 = 1– 10
P0 = - 9
Step- 03:
Thus,
Xk+1 = Xk + 1= 0 + 1= 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1= - 9 + (2 x 1) + 1= - 6
Step- 04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step- 05:
-9 -6 (1, 10)
-6 -1 (2, 10)
-1 6 (3, 10)
6 -3 (4, 9)
-3 8 (5, 9)
8 5 (6, 8)
Algorithm Terminates
These are all points for Octant- 1.
Now, the points of octant- 2 are obtained using the mirror effect by swapping X and Y
coordinates.
(4, 9) (10, 2)
(5, 9) (10, 1)
(6, 8) (10, 0)
Here, all the points have been generated with respect to quadrant- 1-
(4, 9) (- 4, 9) (- 4, - 9) (4, - 9)
(5, 9) (- 5, 9) (- 5, - 9) (5, - 9)
(6, 8) (- 6, 8) (- 6, - 8) (6, - 8)
(8, 6) (- 8, 6) (- 8, - 6) (8, - 6)
(9, 5) (- 9, 5) (- 9, - 5) (9, - 5)
(9, 4) (- 9, 4) (- 9, - 4) (9, - 4)
Given the centre point coordinates (4, - 4) and radius as 10, generate all the points to
form a circle.
Solution-
Points of octane 1of first quadrant:
(9, 5) (13, 9)
(9, 4) (13, 8)
(10, 3) (14, 7)
(10, 2) (14, 6)
(10, 1) (14, 5)
(10, 0) (14, 4)
(13, 9) (- 5, 9) (- 5, - 1) (13, - 1)
(13, 8) (- 5, 8) (- 5, 0) (13, 0)
(14, 7) (- 6, 7) (- 6, 1) (14, 1)
(14, 6) (- 6, 6) (- 6, 2) (14, 2)
(14, 5) (- 6, 5) (- 6, 3) (14, 3)
(14, 4) (- 6, 4) (- 6, 4) (14, 4)
Procedure-
Given-
Step- 01:
Assign the starting point coordinates (X0 , Y0 ) as-
X0 = 0
Y0 = R
Step- 02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
Step- 03:
Suppose the current point is (Xk, Yk) and the next point is (Xk+1, Yk+1).
Find the next point of the first octant depending on the value of decision parameter
Pk.
If the given centre point (X0 , Y0 ) is not (0, 0), then do the following and plot the point-
Xplot = Xc + X0
Yplot = Yc + Y0
Step- 05:
Step- 06:
Given the centre point coordinates (0, 0) and radius as 8, generate all the points to
form a circle.
Solution-
Given-
X0 = 0
Y0 = R = 8
Step- 02:
Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P0 = - 13
Step- 03:
As Pinitial < 0, so case- 01is satisfied.
Thus,
Xk+1 = Xk + 1= 0 + 1= 1
Yk+1 = Yk = 8
Pk+1 = Pk + 4 x Xk+1 + 6 = - 13 + (4 x 1) + 6 = - 3
Step- 04:
This step is not applicable here as the given centre point coordinates is (0, 0).
Step- 05:
(0, 8)
- 13 -3 (1, 8)
-3 11 (2, 8)
11 5 (3, 7)
5 7 (4, 6)
7 (5, 5)
Algorithm Terminates
These are all points for Octant- 1.
Now, the points of octant- 2 are obtained using the mirror effect by swapping X and Y
coordinates.
(0, 8) (5, 5)
(1, 8) (6, 4)
(2, 8) (7, 3)
(3, 7) (8, 2)
(4, 6) (8, 1)
(5, 5) (8, 0)
Now, the points for rest of the part are generated by following the signs of other
quadrants.
The other points can also be generated by calculating each octant separately.
Here, all the points have been generated with respect to quadrant- 1-
(1, 8) (- 1, 8) (- 1, - 8) (1, - 8)
(2, 8) (- 2, 8) (- 2, - 8) (2, - 8)
(3, 7) (- 3, 7) (- 3, - 7) (3, - 7)
(4, 6) (- 4, 6) (- 4, - 6) (4, - 6)
(5, 5) (- 5, 5) (- 5, - 5) (5, - 5)
(6, 4) (- 6, 4) (- 6, - 4) (6, - 4)
(7, 3) (- 7, 3) (- 7, - 3) (7, - 3)
(8, 2) (- 8, 2) (- 8, - 2) (8, - 2)
(8, 1) (- 8, 1) (- 8, - 1) (8, - 1)
(8, 0) (- 8, 0) (- 8, 0) (8, 0)
These are all points of the Circle.