Lec1 CG
Lec1 CG
Lec1 CG
Raster Vector
How to produced Drawn by dots (Pixels) Drawn by sequence of
commands
Resolution Resolution dependent Resolution independent
Scan display Raster scan display Random scan display
Software Photoshop Illustrator
Size Large (depends on resolution) Small
File Extension BMP, TIFF, GIF, JPG, PNG SVG, PDF, AI, EPS, DXF
Details More detailed image Less detailed image
Image Representation
A digital image, or image for short, is composed of discrete pixels or picture
elements. These pixels are arranged in a row-and-column fashion to form a
rectangular picture area, sometimes referred to as a raster. Clearly the total
number of pixels in an image is a function of the size of the image and the
number of pixels per unit length (e.g. inch) in the horizontal as well as the
vertical direction. This number of pixels per unit length is referred to as the
resolution of the image. Thus a 3 x 2 inch image at a resolution of 300pixels per
inch would have a total of 540,000 pixels.
displayed or printed) at 96 pixels per inch. On the other hand, it would measure
1.6 inches by 1.2 inches at 400 pixels per inch.
The ratio of an image's width to its height, measured in unit length or number of
pixels, is referred to as its aspect ratio. Both a 2 x 2 inch image and a512x512
image have an aspect ratio of 1/1, whereas both a 6 x 4 inch image and a
1024x768 image have an aspect ratio of 4/3.
Individual pixels in an image can be referenced by their coordinates. Typically,
the pixel at the lower left corner of an image is considered to be at the origin
(0,0) of a pixel coordinate system. Thus the pixel at the lower right corner of a
640 x 480 image would have coordinates (639,0), whereas the pixel at the upper
right corner would have coordinates (639,479).
The task of composing an image on a computer is essentially a matter of setting
pixel values. The collective effects of the pixels taking on different color
attributes give us what we see as a picture.
( )=( ) -( )
( )=( )-( )
1. Direct Coding
Image representation is essentially the representation of pixel colors. Using
direct coding we allocate a certain amount of storage space for each pixel to
code its color. For example, we may allocate 3 bits foreach pixel, with one bit
for each primary color (see Table 1). This 3-bit representation allows each
primary to vary independently between two intensity levels: 0 (off) or 1 (on).
Hence each pixel can take on one of the eight colors that correspond to the
corners of the RGB color cube.
A widely accepted industry standard uses 3 bytes, or 24 bits, per pixel, with one
byte for each primary color. This way we allow each primary color to have 256
different intensity levels, corresponding to binary values from 00000000 to
11111111. Thus a pixel can take on a color from 256 x 256 x 256 or 16.7million
possible choices. This 24-bit format is commonly referred to as the true color
representation, for the difference between two colors that differ by one intensity
level in one or more of the primaries is virtually undetectable under normal
viewing conditions. Hence a more precise representation involving more bits is
of little use in terms of perceived color accuracy.
A notable special case of direct coding is the representation of black-and-white
(bi-level) and gray-scale images, where the three primaries always have the
same value and hence need not be coded separately. A black-and-white image
requires only one bit per pixel, with bit value 0 representing black and
1representing white. A gray-scale image is typically coded with 8 bits per pixel
to allow a total of 256 intensity or gray levels.
2. Lookup Table
Image representation using a lookup table can be viewed as a compromise
between our desire to have a lower storage requirement and our need to support
a reasonably sufficient number of simultaneous colors. In this approach pixel
values do not code colors directly. Instead, they are addresses or indices into a
table of color values. The color of a particular pixel is determined by the color
value in the table entry that the value of the pixel references.
Figure 3 shows a lookup table with 256 entries. The entries have addresses 0
through 255. Each entry contains a 24-bit RGB color value. Pixel values are
now 1 -byte, or 8-bit, quantities. The color of a pixel whose value is i, where
0 < i < 255, is determined by the color value in the table entry whose address is
i. This 24-bit 256-entry lookup table representation is often referred to as the 8-
bit format. It reduces the storage requirement of a 1000 x 1000 image to one
million bytes plus 768 bytes for the color values in the lookup table. It allows
256 simultaneous colors that are chosen from 16.7 million possible colors.
Image Files
A digital image is often encoded in the form of a binary file for the purpose of
storage and transmission. Among the numerous encoding formats are BMP
(Windows Bitmap), JPEG (Joint Photographic Experts Group File Interchange
Format), and TIFF (Tagged Image File Format). Although these formats differ
in technical details, they share structural similarities.
Figure 6 shows the typical organization of information encoded in an image file.
The file consists largely of two parts:
header and image data.
The values in the image data section may be compressed, using such
compression algorithms as run- length encoding (RLE). The basic idea behind
RLE can be illustrated with a character string "xxxxxxyyzzzz", which takes 12
bytes of storage. Now if we scan the string from left to right for segments of
There are sometimes two versions of the calls that specify RGB values. One
takes RGB values as floating point numbers in the range of [0.0,1.0],
whereas the other takes them as integers in the range of [0,255]. Although
the floating point version is handy when the color values come from some
continuous formula, the floating point values are mapped by the graphics
system into integer values before being written into the frame buffer.
In order to provide basic support for pixel-based image-processing
operations there are calls that look like getPixel(x, y, rgb) for direct coding
or getPixel(x, y, i) for the lookup table representation to return the color or
index value of the pixel at (x, y) back to the application.
There are also calls that read and write rectangular blocks of pixels. A useful
example would be a call to set all pixels to a certain background color.
Assuming that the system uses a current color we would first set the current
color to be the desired background color, and then make a call that looks
like: clear() to achieve the goal.