0% found this document useful (0 votes)
14 views

Chapter15 (Compatibility Mode)

Uploaded by

marshalem786
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Chapter15 (Compatibility Mode)

Uploaded by

marshalem786
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Computer Graphics

with OpenGL 3e

© 2005 Pearson Education


Chapter 15
Graphical file formats

© 2005 Pearson Education


Introduction of graphical file

• Graphical file / image file, is any stored


pictorial representation
• Graphical file in raster-graphics systems
– Graphical representation is referred as raster file
– Color screen display is represented in the frame buffer as
a set of pixel RGB values
– Pixmap, the content of frame buffer
– Compression is applied to reduce the size
• E.g. the file is to stored in a format that does not
supports 24 bits

© 2005 Pearson Education


Image file configurations (1)

• Pixel color values in a raster file


– Store as nonnegative integers
– The range of color values depend on the number of
available bits per pixel
– For example, the value for each component is store in one
byte in a full-color RGB image
• Raw data / raw raster file, uncompressed raster-graphics
file composed of RGB color values
• File format include a header that provide information
about the structure of the file
– For compressed file, it contains table and other details needed
to decode and display the compressed image

© 2005 Pearson Education


Image file configurations (2)

• The ordering of byte in within the raster image


– Big endian, the ordering with the most significant byte first
– Little endian, the ordering with the least significant byte first
• Vector format
– Geometric representation is a list of the coordinate positions
and other information for the object
– For example, straight line segment, fill areas, circular arcs
• Hybrid format / metafiles
– File formats that support both geometric and raster image
representation

© 2005 Pearson Education


Color-reduction methods (1)

• The most popular methods attempt to generate a color


sampling that closely approximate to the original set
of colors
– Sometimes Referred as “quantization”
– It simply replaces one discrete set of color values with a
smaller discrete set of colors
– It does not produce a quantized colors
• Color-reduction methods
– Uniform color reduction
– Popularity color reduction
– Median-cut color reduction

© 2005 Pearson Education


Color-reduction methods (2)

• Uniform color reduction


– Divide each of the R, G, B color level by an integer
and truncate the result
• For example, divide by 2 reduce each components
in a full color representation to 128 levels
Original Re
RGB duced

RGB 
 
255  k  1
 
 
254 
........ ........
 
2  
1 0 
   
0   

© 2005 Pearson Education


Color-reduction methods (3)

• Popularity color reduction


– Retain only the color vale that most frequently in an image
representation
– Procedure of reduction
• Reduce the bit representation for the individual RGB
components
• Modified the set of colors to a count or a histogram, of the
frequency of occurrence for each RGB color components
• Select the k most frequently occurring colors in the image
file

© 2005 Pearson Education


Color-reduction methods (4)

• Median-cut color reduction


– Subdivide the color space for the image file into k sub-regions
and calculate the average color for each of the sub-regions
– Process the same subdivision procedure to each sub-regions
– Continues the process until the original image color block is
subdivided into k sub-blocks

© 2005 Pearson Education


File compression techniques (1)

• To reduce the size of graphics file by replacing the


color value with an encoding that occupies fewer byte
than the original file
• Compression algorithm might involve floating-
point operations which can introduce round-off
errors
– Lossless compression techniques, do not change the values in
an image file
– Lossy compression techniques, create color changes
• File compression techniques
– Run-length encoding
– LZW encoding
– Huffman encoding
– Arithmetic encoding
– Discrete cosine transform

© 2005 Pearson Education


File compression techniques (2)

• Run-length encoding
– Simply searches the image file for contiguous, repeated values
– Reduced file is formed by storing each sequence of repeated
values as the single file value along with the number of
repetitions
– For example : A list indicate that the value 20 occurs 4 times,
followed by 3 non-repeating values 99,68,31, and followed by
8 occurrence of value 40
{20,20,20,20,99,68,31,40,40,40,40,40,40,40,40,…..}

Encoded as :
{4,20,-3,99,68,31,8,40,…..}

© 2005 Pearson Education


File compression techniques (3)

• LZW encoding
– A modification of the earlier LZ, LZ77 and LZ78 pattern-
recognition algorithms
– Replace the repeated pattern with a code
– For example: assign the pattern {128,96} as c1,
{200,30,10} as c2 and {50,240} as c3
{128,96,200,30,10,128,96,50,240,200,30,20,…..}

Encoded as :
{c1,c2,c1,c3,c2,……}

© 2005 Pearson Education


File compression techniques (4)

• Huffman encoding
– Using variable length code for the value in an image file
– Assigns the shortest code for the most frequently occurring
value in the file
– Assigns the longest code for the least frequently occurring
value
– Similar idea as Morse code
• Procedure of Huffman encoding
– Count the number of occurrence of each values in the
input image file
– Assign bit codes with the values according to the
frequency count
• For example, construct a tree

© 2005 Pearson Education


File compression techniques (5)

• Construct a tree for Huffman encoding


– Construct a binary tree with high-frequency values near the
top of the tree and lowest-frequency values as the leaf nodes
– Procedure of construction
• Create the tree from the bottom up, starting with the
low- frequency values
• For each root node
– Assign a numerical label to a sub-tree
– Numerical label can be the sum of the frequency of counts
or node labels
• All left sub-tree are labeled with 1 and right sub-tree
are labeled with 0

© 2005 Pearson Education


File compression techniques (6)

• Construct a tree for Huffman


encoding
– Example of tree-construction
stepsFile value Frequency count
96 8
177 4
141 3
85 3
210 2
43 1
Total values in file 21

© 2005 Pearson Education


File compression techniques (7)

• Construct a tree for Huffman


encoding
– Example of tree-construction
steps

© 2005 Pearson Education


File compression techniques (8)

• Construct a tree for Huffman


encoding
– Example of tree-construction
steps

© 2005 Pearson Education


File compression techniques (9)

• Construct a tree for Huffman encoding


– The complete Huffman binary tree with branch
labeling

© 2005 Pearson Education


File compression techniques (10)

• Arithmetic encoding
– The frequency count in a file is used to obtain numerical
codes for sequences of the file values
– Procedure of arithmetic encoding
• Computes the fraction of the file that is occupied by each
value
• Create a sub-intervals within the unit interval from 0.0 to
1.0
• Map the file fraction to the sub-intervals
• Establish numerical intervals for various combinations of
the file values
• The combinations is encoded with the numerical bounds

© 2005 Pearson Education


File compression techniques (11)

• Arithmetic encoding
– Example
File value Frequency count File fraction Unit-interval range
V1 16 0.20 0.00 – 0.20
V2 24 0.30 0.20 – 0.50
V3 40 0.50 0.50 – 1.00
Total 80 1.00

File value Unit-interval range


V3V1 0.50 – 0.60
V3V2 0.60 – 0.75
V3V3 0.75 – 1.00

© 2005 Pearson Education


File compression techniques (12)

• Discrete Cosine Transform


– Provide faster execution and better color fidelity in a reconstructed
picture at higher compression ratios
– For a list of n numerical values Vk with k = 0,1,…n-1
the set of transformed values is
n1
1 j 
 (2k  1) j  0,1,....,n 

00Vk
V 'j  cj kk  2n)  1
(21 2
cos
cj  ,j cj  ,j 
0 n 0 n
– The original values are recovered with the inverse transformation
n1
 (2k  1) j  k  0,1,...., n 
2n 
Vk   c jV ' j
k   1
0
– Example
cos  209, 211, 207, 192, 148, 88, 63}
{215,

Encoded as
{471.29, 143.81, -67.76, 16.33, 7.42, -4.73, 5.49, 0.05}

© 2005 Pearson Education


File compression techniques (13)

• Discrete Cosine Transform


– Improve efficiency by transforming rectangular blocks of input values
– For a square block of n by n input values, the transformed values
n1 n1
 (2k  1)l   (2 j  1)m  l,m  0,1,...,n 
cos 

V 'lm  c lm j0  jk  2n   2n  1
0 k V cos 

– clm if l =0 or m =0, clm if l ≠0 and m ≠0

c lm  1 c lm 
n n
2
– The n by n set of input values
n1 n1
 (2 j  1)l   (2k  1)m  j,k  0,1,...,n 
cos 

V jk  lm0
0
 c jV j cos 2n   2n  1

© 2005 Pearson Education


Composition of the major file formats (1)

• JPEG (Joint Photographic Experts Group)


– Consists of a large collection of file-compression options
– Four generate file-compression modes
• Lossless mode
– Pattern-recognition scheme is combined with either Huffman
encoding or arithmetic encoding
– Not efficient
• Baseline sequential mode
– Color components are stored in 8 bits
– Compression algorithm combine with the discrete cosine
transformation with Huffman or arithmetic encoding
• Progressive
– Process image file using several passes to generate the
image at varying resolutions
• Hierarchical
– Divides image into a set of sub-images

© 2005 Pearson Education


Composition of the major file formats (2)

• JPEG (Joint Photographic Experts Group)


– JPEG file interchange format (JFIF)
– Operations of JFIF base-line sequential encoding
• Color conversion
• Color sampling
• Discrete Cosine transformation
• Reduction of transformed values
• Huffman encoding
– Still-picture interchange file format (SPIFF), an extension of
JFIF involve more features and options than JFIF

© 2005 Pearson Education


Composition of the major file formats (3)

• TITF (Tag image-file format)


– An efficient format for transferring raster image between
different application and computer systems
– Widely used in application such as medical imaging
– Provide more compression schemes
• PNG (Portable network-graphics format)
– A highly efficient lossless compression scheme for storing
image
– Compression algorithm include Huffman and variation of
LZ encoding
– Very high compression ratio compared with JPEG
• Adobe Photoshop format
– Optimized for fast accessing of large, full-color raster image
– Achieve a very little compression with run-length encoding

© 2005 Pearson Education


Composition of the major file formats (4)

• BMP (Bitmap format)


– Supports image files that contain multiple bits per pixel
• Used for Windows OS application
– Similar pixmap format also called BMP
• Used for IBM OS/2 application
– Usually not compressed, run-length encoding can be applied to
pixmap with 4 or 8 bits per pixel
• GIF (Graphics-adapter format)
– Designed for efficient telephone-line transmission of raster
image
– Provide good compression with LZW algorithm
– Process either monochrome or multicolor pictures
– Pixel values range from 1 to 8 bits, with maximum 256
colors

© 2005 Pearson Education


Composition of the major file formats (5)

• Other file formats


– CGM (Computer-graphics metafile format)
– XBM (X Window system bitmap format)
– XPM (X Window system pixmap format)
– MacPaint (Macintosh paint format)
– PICT (Picture data format)
– PCX (PC paintbrush file format)
– TGA (Truevision graphics-adapter format)

© 2005 Pearson Education

You might also like