Chapter 3 Graphics and Image DataChapter 3 Graphics and Image Data
R iR iRepresentationsRepresentations
3.1 Graphics/Image Data Types
3.2 Popular File Formats
3 3 Further Exploration3.3 Further Exploration
1
3.1 Graphics/Image Data Types3.1 Graphics/Image Data Types3. G ap cs/ age ata ypes3. G ap cs/ age ata ypes
The number of file formats used in multimedia
i lifcontinues to proliferate.
Table 3.1 shows a list of some file formats used in
the popular product Adobe Directorthe popular product Adobe Director.
→ Link to details on Director file formats.
2
11--bit Imagesbit Imagesb t agesb t ages
Pixels, or pels: picture elementsPixels, or pels: picture elements
Each pixel is stored as a single bit (0 or 1),
l f d t bi iso also referred to as binary image.
Such an image is also called a 1-bitg
monochrome image since it contains no
color.color.
Fig. 3.1 shows a 1-bit monochrome image
( ll d "L " b l i di i i(called "Lena" by multimedia scientists —
this is a standard image used to illustrate
many algorithms).
3
Fig. 3.1: Monochrome 1-bit Lena image.g g
4
88--bit Graybit Gray--level Imageslevel Images88 b t G ayb t G ay eve ageseve ages
Each pixel has a gray-value between 0 and
255255.
Each pixel is represented by a single byte; e.g.,
a dark pixel might have a value of 10 and aa dark pixel might have a value of 10, and a
bright one might be 230.
Bitmap: The two-dimensional array of pixelBitmap: The two-dimensional array of pixel
values that represents the graphics/image data.
Image resolution refers to the number ofImage resolution refers to the number of
pixels in a digital image (higher resolution
always yields better quality).
◦ Fairly high resolution for such an image might be 1,
600 × 1, 200, whereas lower resolution might be
640 × 480640 × 480.
5
Frame buffer: Hardware used to store bitmap.
◦ Video card (actually a graphics card) is used for this
purpose.
◦ The resolution of the video card does not have toThe resolution of the video card does not have to
match the desired resolution of the image, but if not
enough video card memory is available then the data
has to be shifted around in RAM for displayhas to be shifted around in RAM for display.
8-bit image can be thought of as a set of 1-bit bit-
planes, where each plane consists of a 1-bitp p
representation of the image at higher and higher
levels of "elevation": a bit is turned on if the image
pixel has a nonzero value that is at or above thatpixel has a nonzero value that is at or above that
bit level.
Fig. 3.2 displays the concept of bit-planesg p y p p
graphically.
6
Fig 3 2: Bit‐planes for 8‐bit grayscale image
7
Fig. 3.2: Bit planes for 8 bit grayscale image.
Multimedia PresentationMultimedia Presentationu t e a ese tat ou t e a ese tat o
Each pixel is usually stored as a byte (a valuep y y (
between 0 to 255), so a 640 × 480 grayscale
image requires 300 kB of storage (640 × 480
= 307, 200).
Fig. 3.3 shows the Lena image again, but thisg g g
time in grayscale.
When an image is printed, the basic strategyg p , gy
of dithering is used, which trades intensity
resolution for spatial resolution to providep p
ability to print multi-level images on 2-level
(1-bit) printers.( ) p
8
Fig. 3.3: Grayscale image of Lena.
9
DitheringDitheringt e gt e g
Dithering is used to calculate patterns of dots such
that values from 0 to 255 correspond to patterns
that are more and more filled at darker pixel
l f i ti 1 bit i tvalues, for printing on a 1-bit printer.
The main strategy is to replace a pixel value by a
larger pattern say 2 × 2 or 4 × 4 such that thelarger pattern, say 2 × 2 or 4 × 4, such that the
number of printed dots approximates the varying-
sized disks of ink used in analog, in halftonesized disks of ink used in analog, in halftone
printing (e.g., for newspaper photos).
◦ Half-tone printing is an analog process that usesp g g p
smaller or larger filled circles of black ink to represent
shading, for newspaper printing.
10
If we use an n×n matrix of on-off 1-bitIf we use an n n matrix of on off 1 bit
dots, we can represent n2+1 levels of
intensity resolutionintensity resolution.
◦ Three dots filled in any way counts as one
i i l lintensity level.
For example, if we use a 2 × 2 dither matrix
11
we can first re-map image values in 0..255 into the
new range 0..4 by (integer) dividing by 256/5.Then,
e.g., if the pixel value is 0 we print nothing, in a 2 ×
2 f i t t t B t if th i l l i 42 area of printer output. But if the pixel value is 4
we print all four dots.
The rule is:The rule is:
◦ If the intensity is > the dither matrix entry then print
an on dot at that entry location: replace each pixel byan on dot at that entry location: replace each pixel by
an n × n matrix of dots.
Note that the image size may be much larger, for a
dithered image, since replacing each pixel by a 4 ×
4 array of dots, makes an image 16 times as large.
12
A clever trick can get around this problem. Suppose we wish
to use a larger 4 × 4 dither matrix such asto use a larger, 4 × 4 dither matrix, such as
An ordered dither consists of turning on the printer output
bit for a pixel if the intensity level is greater than the particular
matrix element just at that pixel positionmatrix element just at that pixel position.
Fig. 3.4 (a) shows a grayscale image of "Lena".The ordered-g ( ) g y g
dither version is shown as Fig. 3.4 (b), with a detail of Lena’s
right eye in Fig. 3.4 (c).
13
An algorithm for ordered dither, with n ×An algorithm for ordered dither, with n
n dither matrix, is as follows:
14
Fig. 3.4: Dithering of grayscale images.
(a): 8-bit grey image "lenagray.bmp". (b): Dithered
version of the image (c): Detail of dithered versionversion of the image. (c): Detail of dithered version.
15
Image Data TypesImage Data Typesage ata ypesage ata ypes
The most common data types for graphics and
image file formats — 24-bit color and 8-bit color.
Some formats are restricted to particular
/ fhardware/operating system platforms, while others
are "cross-platform" formats.
E if f l f hEven if some formats are not cross-platform, there
are conversion applications that will recognize and
translate formats from one system to anothertranslate formats from one system to another.
Most image formats incorporate some variation of
a compression technique due to the large storagea compression technique due to the large storage
size of image files. Compression techniques can be
classified into either lossless or lossy.y
16
2424--bit Color Imagesbit Color Imagesb t Co o agesb t Co o ages
In a color 24-bit image, each pixel is represented by
th b t ll ti RGBthree bytes, usually representing RGB.
◦ This format supports 256 × 256 × 256 possible combined
colors, or a total of 16,777,216 possible colors.
◦ However such flexibility does result in a storage penalty:A
640 × 480 24-bit color image would require 921.6 kB of
storage without any compression.g y p
An important point: many 24-bit color images are
actually stored as 32-bit images, with the extra byte of
data for each pixel used to store an alpha valuedata for each pixel used to store an alpha value
representing special effect information (e.g.,
transparency).
Fi 3 5 h h i f fi b 24 bi iFig. 3.5 shows the image forestfire.bmp, a 24-bit image
in Microsoft Windows BMP format.Also shown are the
grayscale images for just the Red, Green, and Blueg y g j
channels, for this image.
17
Fig 3 5 High resolution color and separate R G B color channel images (a):Fig. 3.5 High-resolution color and separate R, G, B color channel images. (a):
Example of 24-bit color image "forestfire.bmp". (b, c, d): R, G, and B color
channels for this image
18
88--bit Color Imagesbit Color Images88 b t Co o agesb t Co o ages
Many systems can make use of 8 bits of colory y
information (the so-called "256 colors") in
producing a screen image.producing a screen image.
Such image files use the concept of a lookup
table t st re c l r inf rmati ntable to store color information.
◦ Basically, the image stores not color, but instead
j f b h f hi h i lljust a set of bytes, each of which is actually an
index into a table with 3-byte values that specify
the color for a pixel with that lookup table indexthe color for a pixel with that lookup table index.
Fig. 3.6 shows a 3D histogram of the RGB
l f h l “f f b ”values of the pixels in “forestfire.bmp”.
19
Fig. 3.6: 3‐dimensional histogram of RGB colors in "forestre.bmp".
20
Fig. 3.7 shows the resulting 8-bit image, in GIF format.
N h f 8 b 24 bNote the great savings in space for 8-bit images, over 24-bit
ones: a 640 × 480 8-bit color image only requires 300 kB of
storage, compared to 921.6 kB for a color image (again,
ith t an c m ressi n a lied)without any compression applied).
21
Color LookColor Look--up Tables (LUTs)up Tables (LUTs)Co o ooCo o oo up ab es ( U s)up ab es ( U s)
The idea used in 8-bit color images is to store only
h i d d l f h i l Th ifthe index, or code value, for each pixel.Then, e.g., if
a pixel stores the value 25, the meaning is to go to
row 25 in a color look-up table (LUT).p ( )
Fi 3 8 C l LUT f 8 bi l iFig. 3.8: Color LUT for 8-bit color images.
22
A Color-picker consists of an array of fairly
l bl k f l (large blocks of color (or a semi-continuous
range of colors) such that a mouse-click will
select the color indicatedselect the color indicated.
◦ In reality, a color-picker displays the palette colors
associated with index values from 0 to 255.assoc at w t va u s o to .
◦ Fig. 3.9 displays the concept of a color-picker: if the
user selects the color block with index value 2,
th th l t i ith RGB l (0then the color meant is cyan, with RGB values (0,
255, 255).
A very simple animation process is possibleA very simple animation process is possible
via simply changing the color table: this is
called color cycling or palette animation.y g p
23
Fig. 3.9: Color-picker for 8-bit color: each block of theg p
color-picker corresponds to one row of the color LUT
24
Fig. 3.10 (a) shows a 24-bit color image of "Lena", and Fig. 3.10
(b) shows the same image reduced to only 5 bits via dithering(b) shows the same image reduced to only 5 bits via dithering.
A detail of the left eye is shown in Fig. 3.10 (c).
Fig. 3.10: (a): 24-bit color image "lena.bmp". (b):Version with
c l r ditherin (c): Detail f dithered ersi ncolor dithering. (c): Detail of dithered version.
25
How to Devise a Color Lookup TableHow to Devise a Color Lookup Tablepp
The most straightforward way to make 8-bit look-up
l t f 24 bit l ld b t di id th RGBcolor out of 24-bit color would be to divide the RGB
cube into equal slices in each dimension.
The centers of each of the resulting cubes would serveg
as the entries in the color LUT, while simply scaling the
RGB ranges 0..255 into the appropriate ranges would
generate the 8-bit codesgenerate the 8 bit codes.
Since humans are more sensitive to R and G than to B,
we could shrink the R range and G range 0..255 into
th 3 bit 0 7 d h i k th B d tthe 3-bit range 0..7 and shrink the B range down to
the 2-bit range 0..3, thus making up a total of 8 bits.
To shrink R and G, we could simply divide the R or Go s a G, we cou s p y v e t e o G
byte value by (256/8)=32 and then truncate.Then each
pixel in the image gets replaced by its 8-bit index and
the color LUT serves to generate 24-bit colorthe color LUT serves to generate 24-bit color.
26
MedianMedian--cutcut algorithm foralgorithm for ColorColor
R d i P blR d i P blReduction ProblemReduction Problem
A simple alternate solution that does a better job
for this color reduction problem.
a) The idea is to sort the R byte values and find their
di th l ll th th dimedian; then values smaller than the median are
labeled with a "0" bit and values larger than the
median are labeled with a "1" bit.
b) This type of scheme will indeed concentrate bits
where they most need to differentiate between high
l i f l lpopulations of close colors.
c) One can most easily visualize finding the median by
using a histogram showing counts at position 0 255using a histogram showing counts at position 0..255.
d) Fig. 3.11 shows a histogram of the R byte values for
the forestfire.bmp image along with the median of
these values, shown as a vertical line.
27
Fig. 3.11 Histogram of R bytes for the 24-bit color image
"forestfire bmp" results in a "0" bit or "1" bit label for every pixel Forforestfire.bmp results in a 0 bit or 1 bit label for every pixel. For
the second bit of the color table index being built, we take R values
less than the R median and label just those pixels as "0" or "1"
according as their G value is less than or greater than the median of
h G l f h "0" R d b l C R G Bthe G value, just for the "0" Red bit pixels. Continuing over R, G, B
for 8 bits gives a color LUT 8-bit index
28
MedianMedian--Cut AlgorithmCut Algorithme ae a Cut go tCut go t
1. Find the smallest box that contains all the colors in
the imageg
2. Sort the enclosed colors along the longest dimension
of the box.
3 S lit th b i t t i t th di f th3. Split the box into two regions at the median of the
sorted list.
4. Repeat that the above process in steps (2) and (3)p p p ( ) ( )
until the original color space has been divided into,
say, 256 regions.
5 For every box call the mean of R G and B in that5. For every box, call the mean of R, G, and B in that
box the representative (the center) color for the
box.
6. Based on the Euclidean distance between a pixel
RGB value and the box centers, assign every pixel to
one of the representative colors. Replace the pixel byp p p y
the code in a lookup table that indexes
representative colors. 29
3.2 Popular File Formats3.2 Popular File Formats3. opu a e o ats3. opu a e o ats
8-bit GIF : one of the most important8 bit GIF : one of the most important
format because of its historical connection
to the WWW and HTML markup languageto the WWW and HTML markup language
as the first image type recognized by net
bbrowsers.
JPEG: currently the most importantJ y p
common file format.
30
GIFGIFGG
Graphics Interchange Format
GIF standard: (We examine GIF standard because it is
so simple! yet contains many common elements.)
Limited to 8-bit (256) color images only, which, while( ) g y, ,
producing acceptable color images, is best suited for
images with few distinctive colors (e.g., graphics or
drawing)drawing).
GIF standard supports interlacing — successive display
of pixels in widely-spaced rows by a 4-pass display
process.
GIF actually comes in two flavors:
◦ GIF87a:The original specificationGIF87a:The original specification.
◦ GIF89a:The later version. Supports simple animation via a
Graphics Control Extension block in the data, provides
simple control over delay time a transparency index etcsimple control over delay time, a transparency index, etc.
31
GIF87GIF87G 87G 87
For the standard specification, the generalFor the standard specification, the general
file format of a GIF87 file is as in Fig. 3.12.
32
Screen Descriptor comprises a set of attributes that
b l t i i th fil A di t thbelong to every image in the file.According to the
GIF87 standard, it is defined as in Fig. 3.13.
33
Color Map is set up in a very simple fashion as in Fig.
3 14 H th t l l th f th t bl l3.14. However, the actual length of the table equals
2(pixel+1) as given in the Screen Descriptor.
34
Each image in the file has its own Image Descriptor,
d fi d i Fi 3 15defined as in Fig. 3.15.
35
If the "interlace" bit is set in the local Image Descriptor, then
the rows of the image are displayed in a four pass sequencethe rows of the image are displayed in a four-pass sequence
(Fig.3.16).
Fig.3.16: GIF 4–pass interlace display row order.
36
We can investigate how the file header works in practice by
having a look at a particular GIF image Fig 3 7 on page is an 8having a look at a particular GIF image. Fig. 3.7 on page is an 8-
bit color GIF image, in UNIX, issue the command:
od -c forestfire.gif | head -2
and we see the first 32 bytes interpreted as characters:
To decipher the remainder of the file header (after "GIF87a"),
we use hexadecimal:
od -x forestfire.gif | head -2
with the result
37
JPEGJPEGJ GJ G
JPEG:The most important current standard for image
icompression.
The human vision system has some specific limitations
and JPEG takes advantage of these to achieve highJ g g
rates of compression.
JPEG allows the user to set a desired level of quality,
or compression ratio (input divided by output)or compression ratio (input divided by output).
As an example, Fig. 3.17 shows our forestfire. image,
with a quality factor Q=10%.q y
◦ This image is a mere 1.5% of the original size. In comparison,
a JPEG image with Q=75% yields an image size 5.6% of the
original, whereas a GIF version of this image compressesg , g p
down to 23.0% of uncompressed image size.
38
Fig. 3.17: JPEG image with low quality
specified by user.
39
PNGPNGGG
PNG format: standing for Portable Network
G hiGraphics
→ meant to supersede the GIF standard, and
extends it in important waysextends it in important ways.
Special features of PNG files include:
◦ Support for up to 48 bits of color information — aSuppo t o up to 8 b ts o co o o at o a
large increase.
◦ Files may contain gamma-correction information for
correct display of color images as well as alpha channelcorrect display of color images, as well as alpha-channel
information for such uses as control of transparency.
◦ The display progressively displays pixels in a 2-
di i l f hi b h i f i l idimensional fashion by showing a few pixels at a time
over seven passes through each 8 × 8 block of an
image.
40
TIFFTIFF
TIFF: stands for Tagged Image File Format.
The support for attachment of additional
information (referred to as "tags") provides a great
f fdeal of flexibility.
◦ The most important tag is a format signifier: what type
of compression etc is in use in the stored imageof compression etc. is in use in the stored image.
◦ TIFF can store many different types of image: 1-bit,
grayscale, 8-bit color, 24-bit RGB, etc.grayscale, 8 bit color, 24 bit RGB, etc.
◦ TIFF was originally a lossless format but now a new
JPEG tag allows one to opt for JPEG compression.
◦ TheTIFF format was developed by the Aldus
Corporation in the 1980’s and was later supported by
MicrosoftMicrosoft.
41
EXIFEXIF
EXIF (Exchange Image File) is an image format for
digital cameras:
1. Compressed EXIF files use the baseline JPEG format.
2. A variety of tags (many more than in TIFF) are
available to facilitate higher quality printing, since
information about the camera and picture-takinginformation about the camera and picture taking
conditions (flash, exposure, light source, white
balance, type of scene, etc.) can be stored and used
b i f ibl l i l i hby printers for possible color correction algorithms.
3. The EXIF standard also includes specification of file
format for audio that accompanies digital images Asformat for audio that accompanies digital images.As
well, it also supports tags for information needed for
conversion to FlashPix (initially developed by Kodak).
42
GraphicsGraphics AnimationAnimation FilesFilesG ap csG ap cs at oat o eses
A few dominant formats aimed at storing graphics
i i (i i f d i hianimations (i.e., series of drawings or graphic
illustrations) as opposed to video (i.e., series of
images).g )
Difference: animations are considerably less
demanding of resources than video files.
1. FLC is an animation or moving picture file format; it
was originally created by Animation Pro. Another
format, FLI, is similar to FLC., ,
2. GL produces somewhat better quality moving
pictures. GL animations can also usually handle larger
file sizesfile sizes.
3. Many older formats: such as DL or Amiga IFF files,
Apple Quicktime files, as well as animated GIF89 files.
43
PS and PDFPS and PDFS aS a
Postscript is an important language for
d h h d htypesetting, and many high-end printers have
a Postscript interpreter built into them.
P i i b d i lPostscript is a vector-based picture language,
rather than pixel-based: page element
definitions are essentially in terms of vectorsdefinitions are essentially in terms of vectors.
1. Postscript includes text as well as
vector/structured graphics.g p
2. GL bit-mapped images can be included in output
files.
3 E l d P i fil dd ddi i l3. Encapsulated Postscript files add some additional
information for inclusion of Postscript files in
another document.
44
Postscript page description language itselfp p g p g g
does not provide compression; in fact,
Postscript files are just stored as ASCII.
Another text + figures language has begun to
supersede or at least parallel Postscript:p p p
Adobe Systems Inc. includes LZW
compression in its Portable Document
Format (PDF) file format.
◦ PDF files that do not include images have about
the same compression ratio, 2:1 or 3:1, as do files
compressed with other LZW-based compression
toolstools.
45
Some Other JPEG FormatsSome Other JPEG FormatsSo e Ot e J G o atsSo e Ot e J G o ats
MicrosoftWindows:WMF: the native vector
file format for the MicrosoftWindows
operating environment:
1. Consist of a collection of GDI (Graphics
Device Interface) function calls, also native)
to the Windows environment.
2. When a WMF file is "played" (typically usingp y ( yp y g
the Windows PlayMetaFile() function) the
described graphics is rendered.g p
3. WMF files are ostensibly device-
independent and are unlimited in size.p
46
Windows: BMP: the major system standard
graphics file format for Microsoft Windows, used in
Microsoft Paint and other programs. Many sub-
i t ithi th BMP t d dvariants within the BMP standard.
Macintosh: PAINT and PICT:
1 PAINT i i ll d i th M P i t1. PAINT was originally used in the MacPaint program,
initially only for 1-bit monochrome images.
2 PICT format is used in MacDraw (a vector-based2. PICT format is used in MacDraw (a vector based
drawing program) for storing structured graphics.
X-windows: PPM: the graphics format for the Xg p
Window system. PPM supports 24-bit color
bitmaps, and can be manipulated using many public
d i hi didomain graphic editors, e.g., xv.
47
Further ExplorationFurther Explorationu t e p o at ou t e p o at o
→ Link to Further Exploration for Chapter 3.
More information including a complete up-to-date list of
current file formats can be viewed on the textbook website in
Ch 3 f h "F h E l " dChapter 3 of the "Further Exploration" directory.
Other links include:
◦ GIF87 and GIF89 details.Again, these file formats are not soGIF87 and GIF89 details.Again, these file formats are not so
interesting in themselves, but they have the virtue of being simple
and a useful introduction to how such bitstreams are set out.
◦ A shareware program (that is consequently very popular) forp g ( q y y p p )
developing GIF animations.
◦ JPEG considered in detail.
◦ PNG details.
◦ The PDF file format.
◦ The ubiquitous BMP file format.
48

Unit i mm_chap3_graphics and image data representation

  • 1.
    Chapter 3 Graphicsand Image DataChapter 3 Graphics and Image Data R iR iRepresentationsRepresentations 3.1 Graphics/Image Data Types 3.2 Popular File Formats 3 3 Further Exploration3.3 Further Exploration 1 3.1 Graphics/Image Data Types3.1 Graphics/Image Data Types3. G ap cs/ age ata ypes3. G ap cs/ age ata ypes The number of file formats used in multimedia i lifcontinues to proliferate. Table 3.1 shows a list of some file formats used in the popular product Adobe Directorthe popular product Adobe Director. → Link to details on Director file formats. 2 11--bit Imagesbit Imagesb t agesb t ages Pixels, or pels: picture elementsPixels, or pels: picture elements Each pixel is stored as a single bit (0 or 1), l f d t bi iso also referred to as binary image. Such an image is also called a 1-bitg monochrome image since it contains no color.color. Fig. 3.1 shows a 1-bit monochrome image ( ll d "L " b l i di i i(called "Lena" by multimedia scientists — this is a standard image used to illustrate many algorithms). 3 Fig. 3.1: Monochrome 1-bit Lena image.g g 4
  • 2.
    88--bit Graybit Gray--levelImageslevel Images88 b t G ayb t G ay eve ageseve ages Each pixel has a gray-value between 0 and 255255. Each pixel is represented by a single byte; e.g., a dark pixel might have a value of 10 and aa dark pixel might have a value of 10, and a bright one might be 230. Bitmap: The two-dimensional array of pixelBitmap: The two-dimensional array of pixel values that represents the graphics/image data. Image resolution refers to the number ofImage resolution refers to the number of pixels in a digital image (higher resolution always yields better quality). ◦ Fairly high resolution for such an image might be 1, 600 × 1, 200, whereas lower resolution might be 640 × 480640 × 480. 5 Frame buffer: Hardware used to store bitmap. ◦ Video card (actually a graphics card) is used for this purpose. ◦ The resolution of the video card does not have toThe resolution of the video card does not have to match the desired resolution of the image, but if not enough video card memory is available then the data has to be shifted around in RAM for displayhas to be shifted around in RAM for display. 8-bit image can be thought of as a set of 1-bit bit- planes, where each plane consists of a 1-bitp p representation of the image at higher and higher levels of "elevation": a bit is turned on if the image pixel has a nonzero value that is at or above thatpixel has a nonzero value that is at or above that bit level. Fig. 3.2 displays the concept of bit-planesg p y p p graphically. 6 Fig 3 2: Bit‐planes for 8‐bit grayscale image 7 Fig. 3.2: Bit planes for 8 bit grayscale image. Multimedia PresentationMultimedia Presentationu t e a ese tat ou t e a ese tat o Each pixel is usually stored as a byte (a valuep y y ( between 0 to 255), so a 640 × 480 grayscale image requires 300 kB of storage (640 × 480 = 307, 200). Fig. 3.3 shows the Lena image again, but thisg g g time in grayscale. When an image is printed, the basic strategyg p , gy of dithering is used, which trades intensity resolution for spatial resolution to providep p ability to print multi-level images on 2-level (1-bit) printers.( ) p 8
  • 3.
    Fig. 3.3: Grayscale image of Lena. 9 DitheringDitheringt e gte g Dithering is used to calculate patterns of dots such that values from 0 to 255 correspond to patterns that are more and more filled at darker pixel l f i ti 1 bit i tvalues, for printing on a 1-bit printer. The main strategy is to replace a pixel value by a larger pattern say 2 × 2 or 4 × 4 such that thelarger pattern, say 2 × 2 or 4 × 4, such that the number of printed dots approximates the varying- sized disks of ink used in analog, in halftonesized disks of ink used in analog, in halftone printing (e.g., for newspaper photos). ◦ Half-tone printing is an analog process that usesp g g p smaller or larger filled circles of black ink to represent shading, for newspaper printing. 10 If we use an n×n matrix of on-off 1-bitIf we use an n n matrix of on off 1 bit dots, we can represent n2+1 levels of intensity resolutionintensity resolution. ◦ Three dots filled in any way counts as one i i l lintensity level. For example, if we use a 2 × 2 dither matrix 11 we can first re-map image values in 0..255 into the new range 0..4 by (integer) dividing by 256/5.Then, e.g., if the pixel value is 0 we print nothing, in a 2 × 2 f i t t t B t if th i l l i 42 area of printer output. But if the pixel value is 4 we print all four dots. The rule is:The rule is: ◦ If the intensity is > the dither matrix entry then print an on dot at that entry location: replace each pixel byan on dot at that entry location: replace each pixel by an n × n matrix of dots. Note that the image size may be much larger, for a dithered image, since replacing each pixel by a 4 × 4 array of dots, makes an image 16 times as large. 12
  • 4.
    A clever trickcan get around this problem. Suppose we wish to use a larger 4 × 4 dither matrix such asto use a larger, 4 × 4 dither matrix, such as An ordered dither consists of turning on the printer output bit for a pixel if the intensity level is greater than the particular matrix element just at that pixel positionmatrix element just at that pixel position. Fig. 3.4 (a) shows a grayscale image of "Lena".The ordered-g ( ) g y g dither version is shown as Fig. 3.4 (b), with a detail of Lena’s right eye in Fig. 3.4 (c). 13 An algorithm for ordered dither, with n ×An algorithm for ordered dither, with n n dither matrix, is as follows: 14 Fig. 3.4: Dithering of grayscale images. (a): 8-bit grey image "lenagray.bmp". (b): Dithered version of the image (c): Detail of dithered versionversion of the image. (c): Detail of dithered version. 15 Image Data TypesImage Data Typesage ata ypesage ata ypes The most common data types for graphics and image file formats — 24-bit color and 8-bit color. Some formats are restricted to particular / fhardware/operating system platforms, while others are "cross-platform" formats. E if f l f hEven if some formats are not cross-platform, there are conversion applications that will recognize and translate formats from one system to anothertranslate formats from one system to another. Most image formats incorporate some variation of a compression technique due to the large storagea compression technique due to the large storage size of image files. Compression techniques can be classified into either lossless or lossy.y 16
  • 5.
    2424--bit Color ImagesbitColor Imagesb t Co o agesb t Co o ages In a color 24-bit image, each pixel is represented by th b t ll ti RGBthree bytes, usually representing RGB. ◦ This format supports 256 × 256 × 256 possible combined colors, or a total of 16,777,216 possible colors. ◦ However such flexibility does result in a storage penalty:A 640 × 480 24-bit color image would require 921.6 kB of storage without any compression.g y p An important point: many 24-bit color images are actually stored as 32-bit images, with the extra byte of data for each pixel used to store an alpha valuedata for each pixel used to store an alpha value representing special effect information (e.g., transparency). Fi 3 5 h h i f fi b 24 bi iFig. 3.5 shows the image forestfire.bmp, a 24-bit image in Microsoft Windows BMP format.Also shown are the grayscale images for just the Red, Green, and Blueg y g j channels, for this image. 17 Fig 3 5 High resolution color and separate R G B color channel images (a):Fig. 3.5 High-resolution color and separate R, G, B color channel images. (a): Example of 24-bit color image "forestfire.bmp". (b, c, d): R, G, and B color channels for this image 18 88--bit Color Imagesbit Color Images88 b t Co o agesb t Co o ages Many systems can make use of 8 bits of colory y information (the so-called "256 colors") in producing a screen image.producing a screen image. Such image files use the concept of a lookup table t st re c l r inf rmati ntable to store color information. ◦ Basically, the image stores not color, but instead j f b h f hi h i lljust a set of bytes, each of which is actually an index into a table with 3-byte values that specify the color for a pixel with that lookup table indexthe color for a pixel with that lookup table index. Fig. 3.6 shows a 3D histogram of the RGB l f h l “f f b ”values of the pixels in “forestfire.bmp”. 19 Fig. 3.6: 3‐dimensional histogram of RGB colors in "forestre.bmp". 20
  • 6.
    Fig. 3.7 showsthe resulting 8-bit image, in GIF format. N h f 8 b 24 bNote the great savings in space for 8-bit images, over 24-bit ones: a 640 × 480 8-bit color image only requires 300 kB of storage, compared to 921.6 kB for a color image (again, ith t an c m ressi n a lied)without any compression applied). 21 Color LookColor Look--up Tables (LUTs)up Tables (LUTs)Co o ooCo o oo up ab es ( U s)up ab es ( U s) The idea used in 8-bit color images is to store only h i d d l f h i l Th ifthe index, or code value, for each pixel.Then, e.g., if a pixel stores the value 25, the meaning is to go to row 25 in a color look-up table (LUT).p ( ) Fi 3 8 C l LUT f 8 bi l iFig. 3.8: Color LUT for 8-bit color images. 22 A Color-picker consists of an array of fairly l bl k f l (large blocks of color (or a semi-continuous range of colors) such that a mouse-click will select the color indicatedselect the color indicated. ◦ In reality, a color-picker displays the palette colors associated with index values from 0 to 255.assoc at w t va u s o to . ◦ Fig. 3.9 displays the concept of a color-picker: if the user selects the color block with index value 2, th th l t i ith RGB l (0then the color meant is cyan, with RGB values (0, 255, 255). A very simple animation process is possibleA very simple animation process is possible via simply changing the color table: this is called color cycling or palette animation.y g p 23 Fig. 3.9: Color-picker for 8-bit color: each block of theg p color-picker corresponds to one row of the color LUT 24
  • 7.
    Fig. 3.10 (a)shows a 24-bit color image of "Lena", and Fig. 3.10 (b) shows the same image reduced to only 5 bits via dithering(b) shows the same image reduced to only 5 bits via dithering. A detail of the left eye is shown in Fig. 3.10 (c). Fig. 3.10: (a): 24-bit color image "lena.bmp". (b):Version with c l r ditherin (c): Detail f dithered ersi ncolor dithering. (c): Detail of dithered version. 25 How to Devise a Color Lookup TableHow to Devise a Color Lookup Tablepp The most straightforward way to make 8-bit look-up l t f 24 bit l ld b t di id th RGBcolor out of 24-bit color would be to divide the RGB cube into equal slices in each dimension. The centers of each of the resulting cubes would serveg as the entries in the color LUT, while simply scaling the RGB ranges 0..255 into the appropriate ranges would generate the 8-bit codesgenerate the 8 bit codes. Since humans are more sensitive to R and G than to B, we could shrink the R range and G range 0..255 into th 3 bit 0 7 d h i k th B d tthe 3-bit range 0..7 and shrink the B range down to the 2-bit range 0..3, thus making up a total of 8 bits. To shrink R and G, we could simply divide the R or Go s a G, we cou s p y v e t e o G byte value by (256/8)=32 and then truncate.Then each pixel in the image gets replaced by its 8-bit index and the color LUT serves to generate 24-bit colorthe color LUT serves to generate 24-bit color. 26 MedianMedian--cutcut algorithm foralgorithm for ColorColor R d i P blR d i P blReduction ProblemReduction Problem A simple alternate solution that does a better job for this color reduction problem. a) The idea is to sort the R byte values and find their di th l ll th th dimedian; then values smaller than the median are labeled with a "0" bit and values larger than the median are labeled with a "1" bit. b) This type of scheme will indeed concentrate bits where they most need to differentiate between high l i f l lpopulations of close colors. c) One can most easily visualize finding the median by using a histogram showing counts at position 0 255using a histogram showing counts at position 0..255. d) Fig. 3.11 shows a histogram of the R byte values for the forestfire.bmp image along with the median of these values, shown as a vertical line. 27 Fig. 3.11 Histogram of R bytes for the 24-bit color image "forestfire bmp" results in a "0" bit or "1" bit label for every pixel Forforestfire.bmp results in a 0 bit or 1 bit label for every pixel. For the second bit of the color table index being built, we take R values less than the R median and label just those pixels as "0" or "1" according as their G value is less than or greater than the median of h G l f h "0" R d b l C R G Bthe G value, just for the "0" Red bit pixels. Continuing over R, G, B for 8 bits gives a color LUT 8-bit index 28
  • 8.
    MedianMedian--Cut AlgorithmCut Algorithmeae a Cut go tCut go t 1. Find the smallest box that contains all the colors in the imageg 2. Sort the enclosed colors along the longest dimension of the box. 3 S lit th b i t t i t th di f th3. Split the box into two regions at the median of the sorted list. 4. Repeat that the above process in steps (2) and (3)p p p ( ) ( ) until the original color space has been divided into, say, 256 regions. 5 For every box call the mean of R G and B in that5. For every box, call the mean of R, G, and B in that box the representative (the center) color for the box. 6. Based on the Euclidean distance between a pixel RGB value and the box centers, assign every pixel to one of the representative colors. Replace the pixel byp p p y the code in a lookup table that indexes representative colors. 29 3.2 Popular File Formats3.2 Popular File Formats3. opu a e o ats3. opu a e o ats 8-bit GIF : one of the most important8 bit GIF : one of the most important format because of its historical connection to the WWW and HTML markup languageto the WWW and HTML markup language as the first image type recognized by net bbrowsers. JPEG: currently the most importantJ y p common file format. 30 GIFGIFGG Graphics Interchange Format GIF standard: (We examine GIF standard because it is so simple! yet contains many common elements.) Limited to 8-bit (256) color images only, which, while( ) g y, , producing acceptable color images, is best suited for images with few distinctive colors (e.g., graphics or drawing)drawing). GIF standard supports interlacing — successive display of pixels in widely-spaced rows by a 4-pass display process. GIF actually comes in two flavors: ◦ GIF87a:The original specificationGIF87a:The original specification. ◦ GIF89a:The later version. Supports simple animation via a Graphics Control Extension block in the data, provides simple control over delay time a transparency index etcsimple control over delay time, a transparency index, etc. 31 GIF87GIF87G 87G 87 For the standard specification, the generalFor the standard specification, the general file format of a GIF87 file is as in Fig. 3.12. 32
  • 9.
    Screen Descriptor comprisesa set of attributes that b l t i i th fil A di t thbelong to every image in the file.According to the GIF87 standard, it is defined as in Fig. 3.13. 33 Color Map is set up in a very simple fashion as in Fig. 3 14 H th t l l th f th t bl l3.14. However, the actual length of the table equals 2(pixel+1) as given in the Screen Descriptor. 34 Each image in the file has its own Image Descriptor, d fi d i Fi 3 15defined as in Fig. 3.15. 35 If the "interlace" bit is set in the local Image Descriptor, then the rows of the image are displayed in a four pass sequencethe rows of the image are displayed in a four-pass sequence (Fig.3.16). Fig.3.16: GIF 4–pass interlace display row order. 36
  • 10.
    We can investigatehow the file header works in practice by having a look at a particular GIF image Fig 3 7 on page is an 8having a look at a particular GIF image. Fig. 3.7 on page is an 8- bit color GIF image, in UNIX, issue the command: od -c forestfire.gif | head -2 and we see the first 32 bytes interpreted as characters: To decipher the remainder of the file header (after "GIF87a"), we use hexadecimal: od -x forestfire.gif | head -2 with the result 37 JPEGJPEGJ GJ G JPEG:The most important current standard for image icompression. The human vision system has some specific limitations and JPEG takes advantage of these to achieve highJ g g rates of compression. JPEG allows the user to set a desired level of quality, or compression ratio (input divided by output)or compression ratio (input divided by output). As an example, Fig. 3.17 shows our forestfire. image, with a quality factor Q=10%.q y ◦ This image is a mere 1.5% of the original size. In comparison, a JPEG image with Q=75% yields an image size 5.6% of the original, whereas a GIF version of this image compressesg , g p down to 23.0% of uncompressed image size. 38 Fig. 3.17: JPEG image with low quality specified by user. 39 PNGPNGGG PNG format: standing for Portable Network G hiGraphics → meant to supersede the GIF standard, and extends it in important waysextends it in important ways. Special features of PNG files include: ◦ Support for up to 48 bits of color information — aSuppo t o up to 8 b ts o co o o at o a large increase. ◦ Files may contain gamma-correction information for correct display of color images as well as alpha channelcorrect display of color images, as well as alpha-channel information for such uses as control of transparency. ◦ The display progressively displays pixels in a 2- di i l f hi b h i f i l idimensional fashion by showing a few pixels at a time over seven passes through each 8 × 8 block of an image. 40
  • 11.
    TIFFTIFF TIFF: stands forTagged Image File Format. The support for attachment of additional information (referred to as "tags") provides a great f fdeal of flexibility. ◦ The most important tag is a format signifier: what type of compression etc is in use in the stored imageof compression etc. is in use in the stored image. ◦ TIFF can store many different types of image: 1-bit, grayscale, 8-bit color, 24-bit RGB, etc.grayscale, 8 bit color, 24 bit RGB, etc. ◦ TIFF was originally a lossless format but now a new JPEG tag allows one to opt for JPEG compression. ◦ TheTIFF format was developed by the Aldus Corporation in the 1980’s and was later supported by MicrosoftMicrosoft. 41 EXIFEXIF EXIF (Exchange Image File) is an image format for digital cameras: 1. Compressed EXIF files use the baseline JPEG format. 2. A variety of tags (many more than in TIFF) are available to facilitate higher quality printing, since information about the camera and picture-takinginformation about the camera and picture taking conditions (flash, exposure, light source, white balance, type of scene, etc.) can be stored and used b i f ibl l i l i hby printers for possible color correction algorithms. 3. The EXIF standard also includes specification of file format for audio that accompanies digital images Asformat for audio that accompanies digital images.As well, it also supports tags for information needed for conversion to FlashPix (initially developed by Kodak). 42 GraphicsGraphics AnimationAnimation FilesFilesG ap csG ap cs at oat o eses A few dominant formats aimed at storing graphics i i (i i f d i hianimations (i.e., series of drawings or graphic illustrations) as opposed to video (i.e., series of images).g ) Difference: animations are considerably less demanding of resources than video files. 1. FLC is an animation or moving picture file format; it was originally created by Animation Pro. Another format, FLI, is similar to FLC., , 2. GL produces somewhat better quality moving pictures. GL animations can also usually handle larger file sizesfile sizes. 3. Many older formats: such as DL or Amiga IFF files, Apple Quicktime files, as well as animated GIF89 files. 43 PS and PDFPS and PDFS aS a Postscript is an important language for d h h d htypesetting, and many high-end printers have a Postscript interpreter built into them. P i i b d i lPostscript is a vector-based picture language, rather than pixel-based: page element definitions are essentially in terms of vectorsdefinitions are essentially in terms of vectors. 1. Postscript includes text as well as vector/structured graphics.g p 2. GL bit-mapped images can be included in output files. 3 E l d P i fil dd ddi i l3. Encapsulated Postscript files add some additional information for inclusion of Postscript files in another document. 44
  • 12.
    Postscript page descriptionlanguage itselfp p g p g g does not provide compression; in fact, Postscript files are just stored as ASCII. Another text + figures language has begun to supersede or at least parallel Postscript:p p p Adobe Systems Inc. includes LZW compression in its Portable Document Format (PDF) file format. ◦ PDF files that do not include images have about the same compression ratio, 2:1 or 3:1, as do files compressed with other LZW-based compression toolstools. 45 Some Other JPEG FormatsSome Other JPEG FormatsSo e Ot e J G o atsSo e Ot e J G o ats MicrosoftWindows:WMF: the native vector file format for the MicrosoftWindows operating environment: 1. Consist of a collection of GDI (Graphics Device Interface) function calls, also native) to the Windows environment. 2. When a WMF file is "played" (typically usingp y ( yp y g the Windows PlayMetaFile() function) the described graphics is rendered.g p 3. WMF files are ostensibly device- independent and are unlimited in size.p 46 Windows: BMP: the major system standard graphics file format for Microsoft Windows, used in Microsoft Paint and other programs. Many sub- i t ithi th BMP t d dvariants within the BMP standard. Macintosh: PAINT and PICT: 1 PAINT i i ll d i th M P i t1. PAINT was originally used in the MacPaint program, initially only for 1-bit monochrome images. 2 PICT format is used in MacDraw (a vector-based2. PICT format is used in MacDraw (a vector based drawing program) for storing structured graphics. X-windows: PPM: the graphics format for the Xg p Window system. PPM supports 24-bit color bitmaps, and can be manipulated using many public d i hi didomain graphic editors, e.g., xv. 47 Further ExplorationFurther Explorationu t e p o at ou t e p o at o → Link to Further Exploration for Chapter 3. More information including a complete up-to-date list of current file formats can be viewed on the textbook website in Ch 3 f h "F h E l " dChapter 3 of the "Further Exploration" directory. Other links include: ◦ GIF87 and GIF89 details.Again, these file formats are not soGIF87 and GIF89 details.Again, these file formats are not so interesting in themselves, but they have the virtue of being simple and a useful introduction to how such bitstreams are set out. ◦ A shareware program (that is consequently very popular) forp g ( q y y p p ) developing GIF animations. ◦ JPEG considered in detail. ◦ PNG details. ◦ The PDF file format. ◦ The ubiquitous BMP file format. 48