Sie sind auf Seite 1von 36

# CSC4221

Computer Graphics I

1 A. A. Datti
Introduction
Introduction
Applications of Computer Graphics
Graphics System
Hardware
Software
Image Representation
Output Primitives
2D Transformations
2D Viewing

2
*Graphics & Images
*Image processing
*Computer Graphics vs Image Processing
* In computer graphics, a computer is used to create a picture.
Image processing, on the other hand applies techniques to
modify or interpret existing pictures

*Applications:
* Improving picture quality
* Machine perception of visual information, as used in robotics.

## *To apply image processing methods, we first digitize

a photograph or other picture into an image file.
*Definition of Terms
* Digital Image is composed of discrete pixels or picture elements arranged
in row-and-column fashion.

* Image Resolution is the number of pixels per unit length (usually inches)
e.g. A 3 inches X 2 inches image at a resolution of 300 pixels per inch will
have a total of 540,000 pixels

* The size of an image is given as the total number of pixels in the horizontal
direction times the number of pixels in the vertical direction e.g. 640 X
480, or 1024 X 768

## * Display resolution is also measured in pixels in terms of height and width. It

simply means how many pixels can be displayed on the computer screen.
* If your image resolution is bigger than the display resolution, the result would
be part of the image will be out of the display area.

5
* Memory/Storage requirement

* Factors to consider:
* The height of the graphics
* The width of the graphics
* The colour depth or bit depth

## Height X Width X (Colour depth / 8)

*Colour Resolution/Colour Depth
* Each pixel can represent at least 2 possible colours or more.
* Colour resolution or Colour depth/channel depth is
measured in bits.
Colour Depth Calculation Number of Colours
1 bit 21 = 2 2 colours
4 bits 24 = 16 16 colours
8 bits (1 byte) 28 = 256 256 colours
16 bits (2 bytes) 216 = 65,536 65,536 colours
24 bits (3 bytes) 224 = 16,777,216 16,777,216 colours
*Binary (Bitonal) Image
* These images have two possible values of
pixel intensities: black and white.

## * Also called 1-bit monochrome image,

since it contains only black and white.

## * Typicalapplications of bitonal images

handwritten text, line graphics,
engineering graphics etc.

## * Theoutput contains a sequence of black

or white pixels. Binary 1 represents a
black pixel and binary 0 represents a
white pixel.
*Grayscale Image
* They contain several shades of grey.

## * Typical applications of grayscale images

include newspaper photographs (non-
color), magnetic resonance images and
cat-scans.

## * An uncompressed grayscale image can

be represented by n bits per pixel, so
the number of gray levels supported will
be 2n.

## * Forexample, 8-bit Grayscale Image. It

consists of 256 gray levels. A dark pixel
might have a pixel value of 0, a bright
one might be 255.
*Colour Image
* They are characterized by the
intensity of three primary colours
(RGB).

## * For example, 24-bit image or 24 bits

per pixel. There are 16,777,216 (224)
possible colours. In other words, 8
bits for R(Red), 8 bits for G(Green),
8 bits for B(Blue).

## * Sinceeach value is in the range 0-

255, this format supports 256 x 256
x 256 or 16,777,216 different
colours.
*Compression
* Compressing bitmapped images reduces the
amount of storage they require, AND the time they
take to transfer over a network (bandwidth usage)

## * Compression algorithms may be lossless or lossy.

* Lossless: file is compressed, without any loss of
original image quality

## * Lossy: file is compressed, but with (permanent) loss

of original image quality;

11
*Compression: Lossless
* Rearranges data in the image file, but does not
* Works better for graphic style images, and for text-
turned-to-image situations, where large blocks of
colour are more effectively compressed

LZW and Huffman

## * GIF and PNG web file formats use lossless

compression

12
*Compression: Lossy
* Rearranges data in the image file, and discards
data that is (generally) not easily perceived by the
eye

## * The JPEG web file format use lossy compression, and

employs its own compression algorithm

## * Programs like Photoshop allow the designer to control

and compare the degree of compression against the
loss in image quality, and strike a balance

13
*Compression: Quality vs. Size

Image File
quality size

14
*Graphic File formats
*Due to the number of choices available in determining
image representation, it is not surprising that a number
of image formats have evolved. Some examples of image
file formats used for storing images are

## * GIF (Graphics Interchange Format)

* Microsoft Bitmap (bmp)
* PostScript (ps)
* JPEG
* TIFF (Tagged Image File Format)
* TGA (often called Targa)
* PNG, and etc.
* Graphics Interchange Format (GIF)
* 8-bits per pixel, bitmap image format commonly used by the world
wide web
* Uses lossless compression technique
* Compress line art well
* Does not compress photographs well
* Image can have transparent portion
* Can only have a maximum of 256 colours
* GIFs can include more than one image in a single file (can support
simple animation)
* File extension: .gif
*Windows Bitmap (BMP)
* Bitmapped Graphics Format
* Most common format containing pixel by pixel value
* Platform independent
* Support up to 24-bit colour depth
* No compression
* No animation
* File extension: .bmp
* Joint Photographic Expert Group (JPEG)

## * Commonly used standard method of compression for photographic images

* JPEG images are 24-bit colour images (mostly RGB)
* Support a maximum of 16.7 million colours
* Compresses photographs well
* Possible to select compression ratio versus quality
* Lossy compression technique: Losses some image information
* Degradation of image possible with repeated editing and saving
* No transparency
* Only a single image can be stored in one JPEG file (no animation capability)
* File extension: .jpg .jpeg
*Portable Network Graphic (PNG)
* Devised as a replacement for the GIF format in the mid-1990s
* No colour information lost
* Can use all colour depth - supports more than 16.7 million colours
* Compresses well- Lossless Compression Technique
* Image can have transparent portion
* Only a single image can be stored in one PNG file (no animation)
* File extension: .png
*Other Graphic File formats
* RAW Graphics File Format (.raw)
A flexible basic file format for transferring files between applications and
computer platforms. This format consists of a stream of bytes describing
the colour information in the file.

## * Tagged Image File Format (.tif, .tiff)

TIFF is mainly used for exchanging documents between different
applications and different computer platforms. It supports the LZW
method compression for image types.

## * Truevision Targa (.tga)

Developed by Truevision Inc. TGA files is a file format that will support
images suitable for display on Targa hardware but is supported by many
applications on a wide range of platforms.

## * Z Soft Paintbrush (.pcx)

Bitmap graphics file format, originally developed by Z-Soft for use with
PC-Paintbrush. This file format is now used and generated by many
applications and scanners.
*Image Colour Schemes
*Various Colour Schemes
*Several colour schemes (also called colour space, models or
formats) have been developed to represent colour
mathematically.

## *RGB Colour Scheme

*CMY or CMYK Colour Scheme
*HSB or HSI (Hue,Saturation,Brightness/Intensity)
Colour Scheme
*YUV Colour Scheme
*1) RGB Colour Scheme
* Colours are represented by a
numeric triplet specifying R, G
and B intensities. This model is
convenient for CRTs and LCDs
since the numeric values can be
easily mapped to voltages for the
R, G, and B guns.

## * Any colour can be defined by

giving its R, G and B values, or
coordinates, (red,green,blue).
*2) CMY/CMYK Colour Scheme
* CMYK (Cyan,Magenta,Yellow,Black) scheme is widely used for
colour printing. To print a particular colour on a white page, one
must apply inks that subtract (absorb) all colours other than the
one desired.

* Cyan, magenta, and yellow are the subtractive primaries and are
the complements of red, green and blue. Colour is specified by
what is subtracted from white light (which is the sum of R, G and
B).

* Cyan subtracts red from white, and so on. Therefore, white can
only be generated on white paper.
*CMY/CMYK Colour Scheme
* Theoretically, if Cyan, Magenta, and Yellow are mixed, then
all the RGB colours are subtracted, and we get black.
However, in practice inks are not pure, hence a special
black ink is used.

Yellow

Y Red

Green Black

White M
Magenta
C
Blue
Cyan
* White Light : It consists of energy throughout the visible light
spectrum.

* Primary colours : Red (R), Green (G), and Blue (B) are three
primary colours.

## * Additive Mixing : All the colours in the spectrum can be created

with the primary colours. This is called additive colour property
and it works for the mixing of primary colour that are emitting
light. Example, mixing R and G yields yellow. When R, G and B
colours all mixed together, an entire spectrum of colours can be
created.
*Subtractive Mixing
*Secondary colours : Cyan, Magenta and Yellow (CMY) are
secondary colours or subtractive primary colours.

## *Subtractive Mixing : Subtractive colour mixing is based on

reflective colours rather than emissive colours.

## *It generates colour by mixing secondary colours. For example,

mixing magenta and yellow yields red.

## *In subtractive mixing, unwanted colours are selectively

absorbed and the required colour is reflected. The yellow
colour absorbs the blue component, and the magenta absorbs
the green component, resulting in red.

## *Subtractive mixing is used primarily in the printing industry,

by printing the three subtractive colours in differing
proportions on white paper can generate all the colours in the
spectrum.
Additive Colour Mixing Subtractive Colour Mixing

R
Yellow

Green
M Y
W Cyan Black
Red

B C G
Blue Magenta

White
*Image Processing
*Image Processing

## * Analyzing and manipulating images with a computer. Image

processing generally involves three steps:

## * 1. Import an image with an optical scanner or directly through

digital photography.

## * 2. Manipulate or analyze the image in some way. This stage

can include image enhancement and data compression.

## * 3. Output the result. The result might be the image altered in

some way.
*Image Processing Techniques
* Image processing operations may operate directly on pixel data or
on higher level features such as edges, surfaces, and volumes.

## * Image processing operations may be roughly divided into

- Editing
- Filtering
- Compositing
- Geometric transformations
- Conversions

## * Support for a variety of image operations is now becoming

available in page layout and paint programs (such as Photoshop).
*Editing
* The most basic operation is changing individual pixels.

## * Image editors also support cutting, copying, and pasting

selected groups of pixel. A selection might be a simple
rectangular sub-image or an arbitrarily shaped region.

## * Selections are either drawn by the user or calculated by

software (for instance, by examining colour differences
between neighboring pixels).
*Filtering
* Filter operations involve applying a function to every pixel
in an image or selection.

## * The function determines a pixels new value based on its

current value and that of neighboring pixels.

## * Depending on the definition of the function, filtering is used

to blur or sharpen the image, introduce distortions, and
produce a variety of special effects.
*Compositing
* Image compositing is the combination of two or more
images to produce a new image.

## * In general, compositing is specified by mathematical

relationship between the various images. For instance one
image might be produced from the sum of two existing
images.

## * A very large variety of effects are possible.

*Geometric Transformations
* Basic geometric transformations include displacing,
rotating, mirroring, and scaling an image.

## * Other geometric transformations include skewing (slanting)

and warping (an example of warping is mapping a
rectangular selection to an arbitrary four-sided polygon)
*Conversions
* With the variety of image formats available, there is a
frequent need to convert from one format to another.

## * Fortunately, there are a number of public domain software

packages which handle many format conversion tasks. In
addition, image processing software will usually import and
export images in a number of formats.

## * Besides format conversion, there are other operations that

can be considered forms of conversion. These include
image compression or decompression, changing colour
schemes (or models) and changing image depth or
resolution.