Computer Graphics Chapter 1
Computer Graphics Chapter 1
1
What is computer graphics?
2
Cont….
The picture or graphics object may be an engineering drawing,
business graph, architectural structures, a single frame form an
animated movie or a machine parts illustrated for service manual …
The computer graphics is one of the most effective and commonly
used way to communicate the processed information to the user. It
displays the information in the form of graphics objects such as
pictures, charts, graphs and diagrams instead of simple text. Thus we
can say that computer graphics makes it possible to express data in
pictorial form.
3
Cont…
Therefore it is important to understand.
How picture or graphics objects are presented in computer
graphics?
How pictures or graphics objects are prepared for presentation?
How previously prepared pictures or graphics are presented?
How interaction with the picture or graphics object is
accomplished?
4
How images represented?
In computer graphics pictures or graphics objects are presented
as a collection of discrete picture elements called pixels. The
smallest visible element the display hardware can put on the
screen which we can control. The control is achieved by the
intensity and color of pixel which compose the screen.
5
Graphics: Terminology
6
What is an image?
Rectangular grid of pixels- 5x5 grid
If we are using 1 bit per cell, how many bits are needed to present the
picture?
What is a pixel?
Point/Cell in the image that contains color data
Each pixel is made up of bits
Resolution: Details contained in an image
Defined by the number of pixels
5 x5 grid
10
Cones and Color
The cones provide humans with vision during the daylight and are
believed to be separated into three types, where each type is more
sensitive to a particular wavelength
The color signal to the brain comes from the response of the 3 cones to
the spectra being observed. That is, the signal consists of 3 numbers:
11
Color Composition
12
Color Models for Images
RGB Additive Model CMY Subtractive Model
CRT displays have three phosphors (RGB) Cyan, Magenta, and Yellow
which produce a combination of (CMY) are complementary colors
wavelengths when excited with electrons of RGB.
A color image is a 2-D array of (R,G,B) CMY model is mostly used in
integer triplets. These triplets encode how printing devices where the color
much the corresponding phosphor should pigments on the paper absorb
be excited in devices such as a monitor. certain colors (e.g., no red light is
reflected from cyan ink).
Magenta
Black(0,0,0) Green White(0,0,0)
Cyan Blue
Red Yellow
13
Color in Images and Video
Basics of Color
Light and Spectra
Visible light is an electromagnetic wave in the 400 nm - 700 nm
range.
14
Representing Color
000000110011100111001
100001100111010000111
000111000110001111000
011100011110000111000
110111001110011011000
101001100010101000110
001010111011101000110
100101010100001110000
101010100000000001110
1= ON 0
=OFF
24 bit True Color can represent
00 01 10 11 more than 16.7 million unique
Different shades of gray colors. More colors than the
human eye can distinguish!
Raster vs Vector Graphics
Raster graphics: made up of pixels
Resolution dependent
Cannot be scaled without losing quality
Can represent photo realistic elements better
than vector graphics
Text compression
Compression ratio can be as small as 0.2
Great for web-based imaging
Monochrome vs. Grayscale
Monochrome(1 bit image): Grayscale(8 bit gray level image):
Each pixel is stored as a
Each pixel is usually stored as a
single bit (0 or 1)
byte (value between 0 to 255)
A 640 x 480 monochrome
A 640 x 480 grayscale image
image requires 37.5 KB of
requires over 300 KB of storage.
storage.
22
Color Images (24 vs. 8 bit)
24-bit: 8-bit:
Each pixel is represented One byte for each pixel
by three bytes (e.g., RGB) Supports 256 out of the millions
Supports 256 x 256 x 256 colors possible, acceptable color
possible combined colors quality
(16,777,216) Requires Color Look-Up Tables
A 640 x 480 24-bit color (LUTs) -- Pallete
image would require 921.6 A 640 x 480 8-bit color image
KB of storage requires 307.2 KB of storage
Many 24-bit color images (the same as 8-bit grayscale)
are stored as 32-bit
images, the extra byte of
data for each pixel is used
to store an alpha value
representing special effect
information
23
24-bit color
(60KB jpeg)
8-bit color
(30KB gif)
24
System Independent Formats
GIF(GIF87a,GIF89a): JPEG:
Graphics Interchange Format A standard for photographic
(GIF) devised by the UNISYS image compression created by
Corp. and Compuserve, initially the Joint Photographics Experts
for transmitting graphical Group
images over phone lines via Takes advantage of limitations
modems. in the human vision system to
Uses the Lempel-Ziv Welch achieve high rates of
algorithm (compression). compression
Supports only 8-bit (256) color Lossy compression which
images. allows user to set the desired
Supports interlacing level of quality/compression
GIF89a supports simple
animation
25
…Contd
TIFF: Graphics Animation Files:
Tagged Image File Format (TIFF), FLC -- main animation or moving
stores many different types of picture file format, originally
images (e.g., monochrome, created by Animation Pro
grayscale, 8-bit & 24-bit RGB, etc.) FLI -- similar to FLC
Developed by the Aldus Corp. in GL -- better quality moving
the 1980's and later supported by pictures, usually large file sizes
Microsoft Postscript/ PDF:
TIFF is a lossless format (when not
A typesetting language which
utilizing the new JPEG tag which includes text as well as
allows for JPEG compression) vector/structured graphics and bit-
It does not provide any major mapped images
advantages over JPEG and is not as Used in several popular graphics
user-controllable it appears to be programs (Illustrator, FreeHand)
declining in popularity
Does not provide compression, files
are often large
26
System Dependent Formats
Windows(BMP): X-windows(XBM):
A system standard graphics file Primary graphics format for the X
format for Microsoft Windows Window system
It is capable of storing 24-bit bitmap
Supports 24-bit color bitmap
images
Many public domain graphic
Used in PC Paintbrush and other
programs editors, e.g., xv
Used in X Windows for storing
27
PNG: The Future
The Portable Network Graphics (PNG) format was designed to replace the
older and simpler GIF format and, to some extent, the much more complex
TIFF format.
Advantages over GIF:
Alpha channels (variable transparency)
Also known as a mask channel, it is simply a way to associate variable
transparency with an image.
Gamma correction (cross-platform control of image brightness)
Two-dimensional interlacing (a method of progressive display)
GIF uses 1-D interlacing. (see the difference in the example at
http://data.uta.edu/~ramesh/multimedia/examples/interlacing.html )
Better Compression (5-25% better)
Features:
Supports three main image types: truecolor, grayscale and palette-based
(``8-bit''). JPEG only supports the first two; GIF only the third.
Shortcomings:
No Animation
28
Applications of Computer Graphics
Applications of Computer Graphics are:
1. Display of information
2. Design
3. Simulation
4. User Interfaces
1. Displaying Information
- Architectures - floor plans of buildings
- Geographical information - maps
- Medical diagnoses - medical images
- Design engineers - chip layout
- etc.
2. Design
- There are two types of design problems: Overdetermined (posses no
optimal solution) or underdetermined (have multiple solutions).
- Thus, the design is an iterative process.
- Computer-aided Design (CAD) tools assist architectures and designer of
29 mechanical parts with their design.
Applications of Computer Graphics - cont
3. Simulations
- Real-life examples: flight simulators, Command and conquer simulators,
motion-pictures, virtual reality, and medical imaging.
4. User Interface
- Interaction with the computer via visual paradigm that includes windows,
icons, menus, and pointing devices.
A Graphics System
A computer graphics system with the following components:
1. Processor
2. Memory
3. Frame buffer
4. Output devices
5. Input devices
30
A Typical Graphics System
31
Pixels and the Frame Buffer
All graphics systems are raster-based. A picture is produced as an array – the
raster – of picture elements, pixels. Each pixel corresponds to a small area of
the image.
33
Pixels and the Frame Buffer-cont.
Frame buffers may be implemented with Video Random-access Memory
(VRAM) or Dynamic Random-access Memory (DRAM).
The depth of the frame buffer, defines the number of bits that are used for each
pixel and defines the number of colors.
In full-color (true color or RGB) systems, there are 24 (or more) bits per pixel.
Since the beam can be moved directly from one position to any other
35 position, sometimes this device is called random-scan or calligraphic CRT.
Output Devices – cont.
A typical CRT device emits light for only short time - a few milliseconds after
the phosphor is excited by the electron beam.
• Human eyes can see a steady image on most CRT displays when the same
path is retraced or refreshed by the beam at least 50 times per second (50 HZ).
• In a raster system, the graphics system takes pixels from the frame buffer and
displays them as points on the surface of the display. The rate of display must
be high enough to avoid flicker. This is known as the refresh rate.
• There are two fundamental ways that pixels are displayed:
1. noninterlaced: pixels are displayed row-by-row, at refresh rate of
50-85 times per second.
2. interlaced: odd rows and even rows are refreshed alternately. For a
system operating at 60 HZ, the entire display is redrawn 30 times per second.
36
Output Devices – cont.
A typical color CRT have three different colored phosphors (red, green, and
blue) arranged in small groups.
A common style arranges the phosphors in triangular groups called triads, each
consisting of three phosphors (RGB).
The shadow mask ensures that an electron beam excites only phosphors of the
same color.
37
Input Devices
Most graphics systems provide a keyboard and at least one other input device.
The most common devices are the mouse, the joystick, and the data tablet.
Often called pointing devices, these devices allow a user to indicate a particular
location on the display.
38
Objects and Viewers
Our world is the world of three dimensional (3-D) objects. We refer to a
location of a point on an object in terms of some convenience reference
coordinate system.
There is a fundamental link between the physics and the mathematics of image
formation. We exploit this link in our development of computer image
formation.
There are two entities that are part of image formation: object and viewer. The
object exists in space independent of any image-formation process, and of any
viewer.
In computer graphics, we form objects by specifying the positions in space of
various geometric primitives, such as points, lines, and polygons.
In most graphics systems, a set of locations in space, or of vertices, is sufficient
to define, or approximate, most objects.
For example: A line can be defined by two vertices.
39
How many circles do you see on the screen?
40
Objects and Viewers – cont.
To form an image, we must have someone, or something, that is viewing our
objects, be it a human, a camera, or a digitizer. It is the viewer that forms the
image of our objects.
In human visual system, the image is formed on the back of the eye, on the
retina. In a camera, the image is formed on the film plane.
An image may be confused with an object.
Image
object
42
Objects and Viewers – cont.
The object and the viewer exist in a three-dimensional
world. The image that they define, what we find on the
film, is two-dimensional.
43
Light and Images
In our previous discussion of image-formation, we didn’t talk about light. If
there is no light source, an object would be dark and there won’t be anything
visible of the image.
44
Light and Images – cont.
The electromagnetic spectrum includes radio waves, infrared (heat), and a
portion that causes a response in our visual systems, visible light spectrum.
The color of light source is determined by the energy that it emits at various
wavelengths. In graphics, we use the geometric optics which models light sources
as emitters of light energy that have a fixed rate or intensity.
An ideal point source emits energy from a single location at one or more
frequencies equally in all directions. We also assume purely monochromatic
lighting - a source of a single frequency.
45
Ray Tracing
We can model an image by following light from a source. The light that
reaches the viewer, will determine the image-formation.
47
The Human Visual System
Lights enters the eye through Cornea and Lens.
y
yp
z/d
x
Projection Point of (y,z) xp
z/d
50
The Pinhole Camera – cont.
The field or angle view of our camera is the angle made by the largest object
that the camera can image on its film
plane. It can be computed using:
h/2
tan( )
d
1 h
2 tan
2d
The ideal pinhole camera has an infinite depth of field. This camera has two
disadvantages:
1) the pinhole is very small, it admits only a single ray from a point source,
2) the camera cannot be adjusted to have a different angle of view.
For our purposes, we work with a pinhole camera whose focal length is the
distance d from the front of the camera to the film plane. Like the pinhole camera,
computer graphics produces images in which all objects are in focus.
51
The Synthetic – Camera Model
We look at creating a computer-generated image as being similar to forming an
image using an optical system. This paradigm is known as synthetic-camera
model.
The image is formed on the back of
the camera, so we can emulate this
process to create artificial images.
Some basics principals:
1) The specification of the objects
is independent of the specification
An imaging system :
- a viewer (bellows camera)
of the viewer. Expect separate - an object
functions for specifying the objects
and the viewers in the graphic library that you will use.
52
The Synthetic – Camera Model -cont.
2) We can compute the image using simple trigonometric calculations.
53
projector
image plane p
projection of p
center of projection
54
The Synthetic – Camera Model -cont.
We must consider the limited size of the image. Not all objects can be imaged
onto the pinhole camera’s film plane.
The angle of view expresses this limitation.
In our synthetic camera, we place this limitation by placing a clipping
rectangle or clipping window in the projection plane.
Given the location of the center of the projection, the location and orientation of
the projection plane, and the size of the clipping rectangle, we can determine
55which objects will appear in the image.
56
Rendering
Major areas:
Ealiest: PhotoRealism
Recent: Non-Photorealistic Graphics (NPR)
Recent: Image-based Rendering (IBR)
Rendering
Physically based
Newton
Behavior as well as geometry
Materials
Metal, cloth, organic forms, fluids, etc
Procedural (growth) models
Modeling... is hard
Complexity
Shape
Specifying
Realistic constraints
Detail vs concept
Tedious, slow
Modeling is hard
Mathematical challenge
Computational challenge
Interaction challenge
Display challenge (want 3D)
Domain knowledge, constraints
Growth Models
Models
D Johnson and
J D St Germain, Utah
QuickTime™ and a
YUV420 codec decompressor
are needed to see this picture.
National Library of
Medicine
The Programmer’s Interface
There are many sophisticated commercial software products with nice graphical
interfaces. Every one of them has been developed by someone.
Some of us still need to develop graphics applications to interface with these
sophisticated software products.
83
Application Programmer’s Interfaces
The interface between an application program and a graphics system can be
specified through a set of functions that resides in a graphics library. These
specifications are called the application programmer’s interface (API).
The synthetic-camera model is the basis for a number of popular APIs, including
OpenGL, PHIGS, Direct3D, VRML, and JAVA-3D. In order to model
synthetic-camera model we need functions in the API to specify:
Objects
Viewer
Light sources
Material properties
84
The Programmer’s Interface – cont.
Objects are defined by sets of vertices. For simple objects, line, rectangle, and
polygon, there is a simple relationship between a list of vertices and the object.
For more complex objects, there may be multiple ways of defining the object
from a set of vertices.
Most APIs provide similar sets of primitive objects for the user. OpenGL
defines primitives objects through lists of vertices.
Here is an example of how a triangular polygon is defined:
glBegin(GL_POLYGON);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
glEnd();
There are five function calls in this code segment.
85
Create a rectangle of size 2 by 1. The top left (1st point) is still at (0, 0, 0)
OpenGL function format
function name
dimensions
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
86
The Programmer’s Interface – cont.
We can define a viewer or camera in a variety of ways. Looking at the camera
given here, we can identify four types of necessary specifications:
1. Position: The camera location usually is given by the position of the center
of the lens (center of the projection).
2. Orientation: Once we have positioned the camera, we can place a camera
coordinate system with its origin at the center of projection. We can then rotate
the camera independently around the three axes of this system.
3. Focal length: The focal length of the lens determines the
size of the image on the film plane or, equivalently,
the portion of the world the camera sees.
4. Film plane: The back of the camera has a
height, h, and width, w, on the bellows camera,
and in some APIs, the orientation of the back of
Two-point perspective
of a box.
88
The Programmer’s Interface – cont.
OpenGL API allows us to set transformations with complete freedom.
gluLookAt(cop_x, cop_y, cop_z, at_x, at_y, at_z, …);
This function call points the camera from a center of projection toward a
desired point.
gluPerspective(field_of_view, …);
This function selects a lens for a perspective view.
A light source can be defined by its location, strength, color, and directionality.
APIs provide a set of functions to specify these parameters for each source.
Material properties are the attributes of an object. Such properties are defined
through a series of functions. Both the light sources and material properties
depend on the models of light-material interactions supported by the API.
89
Sequence of Images and the Modeling-Rendering Paradigm
OpenGL allows you to write graphical application programs. The images
defined by your programs will be formed automatically by the hardware and
software implementation of the image-formation process.
Sometimes a scene consists of several objects. Although, programmer may
have used sophisticated data structures to model each object and the
relationship among the objects, the rendered scene shows only the outlines of
the objects. This type of image is known as a wireframe image, because we
can see only the edge of surfaces.
A common approach in developing realistic images is to separate the modeling
of the scene from the production of the image – the rendering of the scene.
Thus, the modeler and renderer are done with different software and hardware.
90
Graphics Architectures
On one side of the API is the application program. On the other is some
combinations of hardware and software that implements the functionality of the
API.