CG Module 1
CG Module 1
CG Module 1
(18CS62)
• Image Representation
• Sampling
• Reconstruction
• Quantization & Aliasing
• Image Processing Image composition
• Filtering
• Warping
• Morphing
• Raster Graphics
• Display devices
• Color models
Image morphing
Rendering (Constructing 2D images from 3D
models)
• 3D Rendering Pipeline
• Modeling transformations
• Viewing transformations
• Hidden surface removal
• Illumination, shading, and textures
• Scan conversion, clipping
• Hierarchical scene graphics
• OpenGL
• Global illumination
• Ray tracing
• Radiosity
Modeling (Representing 3D objects)
• Representations of geometry
• Curves
• Surfaces
• Solids
• Procedural modeling
• Fractals mean
Shell A curve or geometrical figure, each
(relating to or of the nature of a fractal)
part of which has the same
statistical character as the whole.
Animation (Simulating changes over
time)
• Key framing
• Kinematics
• Articulated figures
• Motion capture
• Dynamics
• Physically-based simulations
Ice Queen
Graphics Applications
• Graphs and charts
• Computer-aided design
• Virtual-Reality Environments
• Scientific visualization
• Education and Training
• Computer art
• Entertainment
• Image Processing
• Graphical User Interfaces
Data plotting with dramatic effect, commonly used to summarize financial,
statistical, mathematical, scientific, engineering, and economic data for research
reports, managerial summaries, consumer information bulletins and other types of
publications
Graphs and charts
• Computer-aided design
• Virtual-Reality Environments
• Scientific visualization
• Education and Training
• Computer art
• Entertainment
• Image Processing
• Graphical User Interfaces
In design of building, automobiles, aircrafts,
watercrafts, spacecrafts, computers, textiles, home
appliances and a multitude of other products
Entertainment
• Image Processing
• Graphical User Interfaces
Image processing applies techniques to modify or interpret existing pictures (photographs, TV
scans).to apply image processing methods, the image must be digitized first. Medical
applications also make extensive use of image processing techniques for picture enhancement,
simulations of surgical operations. It used to improve picture quality, analyze or recognize
visual• patterns.
Graphs and charts
• Computer-aided design
• Virtual-Reality Environments
• Scientific visualization
• Education and Training
• Computer art
• Entertainment
Image Processing
• Graphical User Interfaces
User is provided with point and click facility to select menu items, icons and objects on the
screen. User can manage multiple windows simultaneously. Word-processing spreadsheets and
desktop-publishing programs are typical applications that take advantage of such user
interface techniques.
• Graphs and charts
• Computer-aided design
• Virtual-Reality Environments
• Scientific visualization
• Education and Training
• Computer art
• Entertainment
• Image Processing
Graphical User Interfaces
Basic Graphics System
Output device
Input devices
Image formed in FB
Also…
Computer
Graphics
Model Image
Pattern
Recognition
Image
Processing
From model to image
Graphics pipeline
Cylinder:
x2 y2 r 2
0 zh
Geometric modeling Local or modeling coordinates
From model to image
World coordinates
From model to image
Look at cylinders,
project on virtual screen
Viewing coordinates
Visible surfaces, shading
From model to image
1
Display:
0
1024
Display on screen:
• Horizontal
Horizontal scan
scan rate
rate
-- the
the number
number of of scan
scan lines
lines per
per second
second that
that the
the CRT
CRT is
is able
able to
to display
display
-- refresh
refresh rate
rate ** number
number ofof scan
scan lines
lines per
per frame
frame
Color CRT Monitor
Displays color pictures by using a combination of phosphors that emit different-
colored light and merges to form a single perceived color.
CRT
Shadow Mask
Electron Guns
Red Input
Green
Input
Blue Input
Deflection
Yoke Red, Blue,
and Green
Phosphor Dots
Beam Penetration Method
• Coat the screen with layers of different
colored phosphors.
Beam of slow electrons excite outer red
layer, beam of very fast electrons penetrates
through red layer and excites the inner green
layer.
(Drawback)Limited to number of colors
since only two colors used.
(Drawback)Picture quality is not as good as
with the other method.
• Dot Pitch –the spacing between pixels on
a CRT, measured in millimeters.
Generally, the lower the number, the
more detailed the image.
• Uses 3 phosphor color dots at each pixel position, each emitting
one of red, blue and green lights.
• It has 3 electron guns, one for each color dot and shadow mask Shadow Mask
grid just behind the phosphor-coated screen.
• Shadow mask contains series of holes aligned with phosphor dot
Method
patterns, one hole for each phosphor triad.
• When the 3 beams pass through a hole in the shadow mask, they
activate a dot triangle, which appears as small color spot on the
screen. The phosphor dots in the triangles are arranged so that
each electron beam can activate only its corresponding color dot
when it passes through the shadow mask.
• The number of electrons in each beam controls the amount of
red, blue and green light generated by the triad.
• Another configuration is the in-line arrangement, in which the
electron guns and corresponding color dots are aligned along one
scan line.
• Color CRTs in graphics systems are designed as RGB monitors
Architectures for displaying objects
• Vector system Architecture (Random-Scan)
Line drawing and stroke drawing in a random order
:
JMP
display buffer
Raster Display (since 1970s)
• Raster system consists of display processor (input, refreshing, scan converting),
video controller, buffer memory (frame buffer), CRT.
• The refresh buffer stores the display primitives(lines char and solid shaded or
patterned areas), rather than display list or display program.
• Raster: set of horizontal raster lines each a row of individual pixels and thus
stored as a matrix of pixels representing entire screen.
• Video controller reads these pixel contents to produce the actual image on the
screen, one raster line at a time, from top to bottom and then back to top.
• need refresh the raster display (e.g., 60Hz)
Raster Display
Host Computer
Display Interaction
cmds data
Display Processor
Lucy
Video Controller Lucy
Frame buffer
Monitor
Basic definitions
Video raster devices display an image by sequentially
drawing out the pixels of the scan lines that form the
raster.
• Raster: A rectangular array of points or dots.
• Pixel (Pel, picture elements): One dot or picture element of the raster, defined as
smallest addressable area on screen.
• Scan line: A row of pixels.
• Resolution: # of pixel positions that can be plotted.
• Aspect Ratio: # of horizontal points to vertical points(or vice versa).
• Depth: # of bits per pixel in a frame buffer.
• Bitmap: a frame buffer with one bit per pixel
• Pixmap: a frame buffer with multiple bits per pixel.
• Horizontal retrace: return to the left of the screen, after refreshing each scan
line.
• Vertical retrace: electron beam returns to the top left corner of the screen to
begin the next frame.
• Refresh rates are described in units of cycles per seconds, or Hertz(Hz).
Scanning An Image
• Frame: The image to be scanned out on the CRT.
• Some minimum number of frames must be redisplayed (or refreshed) each second
to eliminate flicker in the image.
X
Linear address
Horizontal
address Raster-scan & vertical
generator Deflection signal
Frame Y
buffer address
Data Pixel Intensity
values or color
Types of refresh
• Interlaced (mostly for TV for reduced flickering effect -National
Television System Committee NTSC) each frame is displayed
in two passes or two fields
First pass: The beam sweeps across every other scan line form
top to bottom. odd-field: odd-numbered scan lines
Second pass: After vertical retrace, the beam then sweeps out
the remaining scan lines. even-field: even-numbered scan lines
Refresh rate: e.g., NTSC: 60Hz (60 fields per second); 30
frame/s. PAL(Phase Alternating Line) : 50Hz
• Non-interlaced (mostly for monitor) Odd-field
refresh rate: e.g., 60Hz or more Even-field
Display Processor
• Also called either a Graphics Controller or Display Co-Processor
• Specialized hardware to assist in scan converting output primitives into
the frame buffer.
• Fundamental difference among display systems is how much the display
processor does versus how much must be done by the graphics subroutine
package executing on the general-purpose CPU.
Architecture of a raster-graphics system with a
display processor
Peripheral
Devices CPU
System bus
Display
Video Display
Frame
Controller Processor Buffer
Memory
Frame Buffer
1 bit
2 levels
Electron
Gun
3-Bit Color Display
3
red
green
blue
R 0 1 0 0 1 0 1 1
G 0 0 1 0 1 1 0 1
B 0 0 0 1 0 1 1 1
8
True Color Display
24 bit planes, 8 bits per color gun.
8
2 = 16,777,216 colors
24
Green
(1280 X 1024 X 24 ) = 3,840 KB or Blue
3,932,160 bytes
Color Look-up Table
LUT
LUT (Look-Up
(Look-Up Table)
Table)
•• LUT
LUT has
has as
as many
many entries
entries as
as there
there are
are pixel
pixel values,
values, values
values in
in the
the bit
bit planes
planes are
are used
used as
as indices
indices in
in one
one or
or more
more
LUT.
LUT.
•• A
A pixel
pixel value
value is
is used
used not
not to
to control
control the
the beam
beam directly,
directly, but
but rather
rather as
as an
an index
index into
into the
the look-up
look-up table.
table.
•• The
The table
table entry’s
entry’s value
value is
is used
used to
to control
control the
the intensity
intensity or
or color
color of
of the
the CRT.
CRT.
for
for example:
example:
If
If each
each pixel
pixel consists
consists ofof 88 bits
bits in
in the
the frame
frame buffer
buffer the
the LUT
LUT requires
requires aa table
table with
with 256
256 entries.
entries.
Pixel
Pixel value 67
value 67 access
access the
the content
content in
in the
the entry
entry 67
67 of
of the table
the table use
use the
the color
color
content
content to
to control
control the
the CRT
CRT beam
beam
•• The
The total
total number
number of of bits
bits in
in each
each table
table entry
entry is
is called
called the
the width
width of
of the
the LUT,
LUT,
which
which isis the
the capability
capability for
for providing
providing allall possible
possible colors
colors
•• The
The look-up
look-up operation
operation isis done
done forfor each
each pixel
pixel on
on each
each display
display cycle,
cycle, fast
fast access
access of
of the
the table
table is
is required.
required.
•• LUT
LUT can
can be
be loaded
loaded on
on program
program command.
command.
Color Map Look-Up Tables
y RED
max
GREEN
255
BLUE
1
1
0
y 0
0 67 Pixel displayed
0
1 1001 1010 0001
0
67 100110100001 at x', y'
R G B
Pixel in
bit map 0
0 at x', y'
0 x x
max
Fig. LUT Video look-up table organization. A pixel with value 67 (binary 01000011) is displayed on the
screen with the red electron gun at 9/15 of maximum, green at 10/15, and blue at 1/15. This look-up table is
shown with 12 bits per entry. Up to 24 bits per entry are common.
Pseudo Color: 2 x 24 Color Map LUT 8
• The number of the bit planes in the frame buffer determines the number of
colors displayable on the screen simultaneously
• The width of the LUT determines the number of possible colors that we can
choose from (also called the color palette)
• Example:
8 bit planes 288 or 256 colors can be displayed simultaneously
A LUT width of 12 bits color palette consists of 21212 colors in all
Flat Panel Display
• The term flat panel display refers to a class of video device that have reduced
volume, weight, power requirement and are thinner than CRTs (that could be
hung on walls or worn on wrists).
• We can separate flat panel display in two categories:
1. Emissive displays (Emitters): - convert electrical energy into light.
Eg. Plasma panel,
Thin film electroluminescent displays
Light emitting diodes(LED).
2. Non emissive displays (Non Emitters): - use optical effects to convert sunlight or
light from some other source into graphics patterns.
Eg. Liquid Crystal Display(LCD).
Plasma Panels
• This is also called gas discharge displays.
• It is constructed by filling the region between two glass
displays
plates with a mixture of gases that usually includes neon.
• A series of vertical conducting ribbons is placed on one
glass panel and a set of horizontal ribbon is built into the
other glass panel.
• Firing voltage is applied to a pair of horizontal and vertical
conductors cause the gas at the intersection of the two
conductors to break down into glowing plasma of
electrons and ions.
• Refresh rate: 60 times per second.
• Separation between pixels is provided by the electric field
of conductor.
• Disadvantage: strictly monochromatic device
Thin Film Electroluminescent Displays
• It is similar to plasma panel display but region between
the glass plates is filled with phosphors such as Zinc
sulfide doped with magnesium instead of gas.
• When sufficient voltage is applied the phosphors
becomes a conductor in area of intersection of the two
electrodes.
• Electrical energy is then absorbed by the manganese
atoms which then release the energy as a spot of light
similar to the glowing plasma effect in plasma panel.
• It requires more power than plasma panel.
• In this good color displays are difficult to achieve.
Light Emitting Diode (LED)
OpenGL Motif
widget or similar GLUT
GLX, AGL
or WGL GLU
Texture
Memory
Pixel
Operations
OpenGL Functions
• Primitives
• Points
• Line Segments
• Polygons
• Attributes
• Transformations
• Viewing
• Modeling
• Control
• Input (GLUT)
OpenGL State
• OpenGL is a state machine
• OpenGL functions are of two types
• Primitive generating
• Can cause output if primitive is visible
• How vertices are processes and appearance of primitive are controlled by the state
• State changing
• Transformation functions
• Attribute functions
Lack of Object Orientation
• OpenGL is not object oriented so that there are multiple functions for a
given logical function, e.g. glVertex3f, glVertex2i,
glVertex3dv,…..
• Underlying storage mode is the same
• Easy to create overloaded functions in C++ but issue is efficiency
OpenGL Function Format
function name
3 is Dimension can be 2 or 3
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
OpenGL #defines
• Most constants are defined in the include files gl.h, glu.h and
glut.h
• Note #include <glut.h> should automatically include the others
• Examples
• glBegin(GL_PLOYGON)
• glClear(GL_COLOR_BUFFER_BIT)
• Include files also define OpenGL data types: Glfloat, Gldouble,….
Program Structure
• Most OpenGL programs have a similar structure that consists of the following functions
• main():
• defines the callback functions
• opens one or more windows with the required properties
• enters event loop (last executable statement)
• init(): sets the state variables
• viewing
• Attributes
• callbacks
• Display function
• Input and window functions
OpenGL Primitives
GL_POINTS GL_POLYGON
GL_LINES GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLES
GL_QUAD_STRIP
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
Attributes
• Attributes are part of the OpenGL state and determine the appearance of objects
• Color (points, lines, polygons)
• Size and width (points, lines)
• Stipple pattern (lines, polygons)
• Polygon mode
• Display as filled: solid color or stipple pattern
• Display edges
• Display vertices
Graphics Pipelines
• Graphics processes generally execute sequentially
• Typical ‘pipeline’ model
• There are two ‘graphics’ pipelines
• The Geometry or 3D pipeline
• The Imaging or 2D pipeline
04/19/21
Narendra V G CSE MIT 105
06:46 AM
2D Graphics Pipeline
Clipping
Object window to
Object Applying
subset viewport
World Coordinates world window
mapping
Object
Display Rasterization
Screen coordinates
Rasterization (Scan Conversion)
6
5
? Which intermediate
4
pixels to turn on?
3
2
1
0 1 2 3 4 5 6 7 8 9 10 11 12
Line Drawing Algorithm
• Slope-intercept line equation
• y = mx + b Equation of Line where m is slope & b is intercept
• Given two end points (x0,y0), (x1, y1), how to compute m and b?
dy y1 y 0 b y 0 m * x0
m
dx x1 x0
(x1,y1)
dy
(x0,y0)
dx
Line Drawing Algorithm
• Numerical example of finding slope m:
• (Ax, Ay) = (23, 41), (Bx, By) = (125, 96)
By Ay 96 41 55
m 0.5392
Bx Ax 125 23 102
Digital Differential Analyzer (DDA): Line
Drawing Algorithm
Walk through the line, starting at (x0,y0)
x=x+1 y=y+1*m
Until x == x1
(x0, y0)
DDA Line Drawing Algorithm (Case b: m >
1) x = x0 y = y0
1
x k 1 xk (x1,y1)
m Illuminate pixel (round(x), y)
y = y0 + 1 x = x0 + 1 * 1/m
y=y+1 x = x + 1 /m
(x0,y0) Until y == y1
DDA Line Drawing Algorithm Pseudocode
compute m;
if m < 1:
{
float y = y0; // initial value
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
} Note: setPixel(x, y) writes current color into pixel in column x and row y in
frame buffer
DDA Line Drawing Algorithm
Drawbacks
• DDA is the simplest line drawing algorithm
• Not very efficient
• Round operation is expensive
• Optimized algorithms typically used.
• Integer DDA
• Eg. Bresenham algorithm (Hill, 10.4.1)
• Bresenham algorithm
• Incremental algorithm: current value uses previous value
• Integers only: avoid floating point arithmetic
• Several versions of algorithm: we’ll describe midpoint version of
algorithm
Bresenham’s Line-Drawing Algorithm
• Accurate and efficient
• Uses only incremental integer calculations
The method is described for a line segment with a positive slope less
than one
The method generalizes to line segments of other slopes by considering
the symmetry between the various octants and quadrants of the xy plane
Bresenham’s Line-Drawing Algorithm
11
10
10 11 12 13
Bresenham’s Line-Drawing Algorithm
yk
• dupper=(yk+1)-y
xk+1
= yk+1 -m(xk + 1)-b
• dlower- dupper= 2m(xk + 1)-2yk+2b-1
• Rearrange it to have integer calculations:
m=Δy/Δx
Decision parameter: pk= Δx(dlower- dupper)=2Δy.xk - 2Δx. yk + c
The Decision Parameter
Decision parameter: pk= Δx(dlower- dupper)=2Δy.xk - 2Δx. yk + c
1. Input the twoline endpoints and store the left endpoint in (x0 ,y0).
2. Load (x0 ,y0) into the frame buffer; that is, plot the first point.
3. Calculate constants Δx, Δy, 2Δy, and 2Δy - 2Δx, and obtain the starting value for the decision
parameter as
p0=2 Δy - Δx
4. At each xk along the line, starting at k = 0, perform the following test:
If pk < 0, the next point to plot is (xk+1, yk) and
pk+1=pk + 2Δy
Otherwise, the next point to plot is (xk+1, yk+1) and
pk+1=pk + 2Δy - 2Δx
5. Repeat step 4 Δx -1 times.
Trivial Situations: Do not need Bresenham
y yc R 2 ( x xc ) 2
• Explicit: y = f(x)
y R2 x2
We could draw a quarter circle by
incrementing x from 0 to R in unit steps
and solving for +y for each step.
• Decision variable d is x 2 + y 2 – r 2
• Then d = F(M) 0 SE
• Or d = F(M) < 0 E
F (M) 0 SE
current
pixel E
ideal
curve M
SE
F (M) < 0 E
E
ideal
curve
M
SE
As in the Bresenham line algorithm we use a decision
variable to direct the selection of pixels.
Use the implicit form of the circle equation
p = F (M ) = x 2 + y 2 – r 2
Midpoint coordinates are ( xk 1, yk 1 )
2
Assuming we have just plotted point at (xk,yk) we determine whether move E or SE
by evaluating the circle function at the midpoint between the two candidate pixel
positions pk Fcirc ( xk 1, yk 1 )
2
( xk 1) 2 ( yk 1 ) 2 r 2
2
pk is the decision variable
if pk <0 the midpoint is inside the circle
Thus the pixel above the midpoint is closer to the ideal circle, and we select pixel on
scan line yk. i.e. Go E
If pk >0 the midpoint is outside the circle.
Thus the pixel below the midpoint is closer to the ideal circle, and we select pixel
on scan line yk-1. i.e. Go SE
pk 1 Fcirc ( xk 1 1, yk 1 1 )
2
[( xk 1) 1]2 ( yk 1 1 ) 2 r 2
2
recursive definition for successive decision parameter values p
pk 1 Fcirc ( xk 1 1, yk 1 1 )
2
[( xk 1) 1]2 ( yk 1 1 ) 2 r 2
2
pk 1 pk 2( xk 1) ( yk21 yk2 ) ( yk 1 yk ) 1
x0 = 0, y0 = r
Initial decision variable found by evaluating circle function at first midpoint test
position
p0 Fcirc (1, r 1 )
2
1 (r 1 ) 2 r 2
2
5
r
4
For integer radius r p0 can be rounded to p0 =1-r
since all increments are integer.
• r=10
• End of Module 1