Lecture Two Compression & File Specification Standards.

40
Lecture Two Compression & File Specification Standards

Transcript of Lecture Two Compression & File Specification Standards.

Page 1: Lecture Two Compression & File Specification Standards.

Lecture Two

Compression &

File Specification Standards

Page 2: Lecture Two Compression & File Specification Standards.

2

Last week

• We looked at:– Raster and vector graphics– Implications for multimedia

• Use of colour• Image size

Page 3: Lecture Two Compression & File Specification Standards.

3

Overview

By the end of this lecture you will be familiar with:• Compression standards

– Lossy– Lossless

• File specification standards– Main types used in multimedia– Where and when best used

Page 4: Lecture Two Compression & File Specification Standards.

4

Image Storage/RetrievalFundamental requirement of graphics system

software– basic operation: saving the values contained in the

frame buffer directly to file• note: colour table values may also have to be stored

– 512x512x8-bit image requires 256kbytes– animated sequences may require 25-50 such frames of

data per second

Page 5: Lecture Two Compression & File Specification Standards.

5

Image Compression/CodingTo decrease the amount of storage space

required– Lossy techniques (e.g. JPEG)

• apply some filter function to the image which reduces the quantity of data, but cannot reproduce the original image

– Lossless techniques (e.g. BMP’s RLE, TIFF’s LZW)• Lossless refers to compression schemes that conserve space

on disk without sacrificing any data in the image• original image is always reproduced• Slows down the open and save operations

Page 6: Lecture Two Compression & File Specification Standards.

6

Lossless technique: Run-Length Encoding

Uses principle of scanline coherence– if one pixel on a scanline is of a certain colour, the next

is likely to be of the same colour– store scanline data as (colour, number) pairs, where

number counts the consecutive pixels of the same colour

– storage requirements increase as run lengths get smaller

Page 7: Lecture Two Compression & File Specification Standards.

7

ExampleAn image consists of 8x8 pixels

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

Page 8: Lecture Two Compression & File Specification Standards.

8

4 bits/pixel

W W W W G B R R

W W W W R R R R

W W W W G B R R

W W W W R R G G

W R R G B B R R

R R R B B B B B

B B R R G B G G

B B R R R R G G

8x8 image x 4 bits/pixel = 256 bits

Page 9: Lecture Two Compression & File Specification Standards.

9

Run EncodingW4 G1 B1 R2

W4 R4

W4 G1 B1 R2

W4 R2 G2

W1 R2 G1 B2 R2

R3 B5

B2 R2 G1 B1 G2

B2 R4 G2

28 runs @ 4 bits (colour)+ 3 bits (number) = 196 bits

Page 10: Lecture Two Compression & File Specification Standards.

10

Quadtree Encoding• Uses principle of pixel coherence

– 2D variation on scanline coherence– image is recursively subdivided (quartered) into

homogenous areas (areas of constant colour)– image is stored as a tree structure where

• root node represents the entire image• leaf nodes represent regions of constant colour• non-leaf nodes each have 4 children representing the

area subdivision

Page 11: Lecture Two Compression & File Specification Standards.

11

Example

W W W W G B R R

W W W W R R R R

W W W W G B R R

W W W W R R G G

W R R G B B R R

R R R B B B B B

B B R R G B G G

B B R R R R G G

8x8 image, 4 bits/pixel = 256 bits

Page 12: Lecture Two Compression & File Specification Standards.

12

Quadtree Encoding-1

W -1 -1 -1

-1 R -1 -1 -1 -1 B R B -1 -1 G

G B R R G B R R R R G G W R R R R G R B R R B B G B R R

45 nodes @ 5 bits = 225 bits

Page 13: Lecture Two Compression & File Specification Standards.

13

Compression Ratios

• Definition:

CR = Uncompressed image size

Compressed image size

• In previous examples:

Run-length CR = 256/196 = 1.3

Quadtree CR = 256/225 = 1.14

Page 14: Lecture Two Compression & File Specification Standards.

14

Discrete Cosine Transform (DCT)

Original ImageN×N square block:

pixels valuesN×N

DCT coefficients

Block Partitioning

DC

T

Quantization

QuantizationTable

cn....c3c2c1DC

AC

DC

AC

Page 15: Lecture Two Compression & File Specification Standards.

15

JPEG Compression

Pixel blocking DCT Quantisation RLE

Huffman codingData packing

Page 16: Lecture Two Compression & File Specification Standards.

File Specification Standards

Page 17: Lecture Two Compression & File Specification Standards.

17

Standards - Why Bother?

• Portability– platform independence– programmer portability

• Not tied to proprietary formats– cost– availability

• Problem of plethora of standards– e.g. Photoshop supports more than 20 file formats

Page 18: Lecture Two Compression & File Specification Standards.

18

Common image file formats

• BMP raster widely used

- Windows Bitmap is native format for Microsoft’s Paint

- Supports lossless compression using RLE (Run-Length Encoding)

- Images with up to 16 million colours

• GIF raster Internet use

- CompuServe’s GIF (Graphics Interchange Format)

- Means of compressing files for quick transfer over modem

- Supports lossless compression using LZW (Lempel-Ziv-Welch)

- Images limited to only 256 colours

Page 19: Lecture Two Compression & File Specification Standards.

19

Common image file formats cont…

• JPEG raster compressed- Format named after the people who designed JPEG (Joint Photographic Expert Group)- Lossy compression scheme i.e. scarifies image quality to conserve space on disk – Data lossess can be controlled in Photoshop - Evaluates image in 88-pixel blocks using ADCT (Adaptive Discrete Cosine Transform)- Best use for photographs

• PNG raster internet use- Introduced to replace .gif- Has a number of advantages over .gif

Page 20: Lecture Two Compression & File Specification Standards.

20

Common image file formats cont…

• TIFF raster large standard- Aldus in early days of Mac to standardise the growing population of scanned images developed TIFF (Tagged Image File Format)- Widely used format both in Mac and PC platforms- Uses lossess compression techniques such as LZW, ZIP as well as lossy technique such JPEG.

• SWF vector Used by Flash-vector graphics standard used to create animations for the web

• WMF / CGM vector specialist use

Page 21: Lecture Two Compression & File Specification Standards.

21

Common video file formats

• MPEG / MPG / MPV• AVI• MOV - QuickTime™

many other proprietary formats - e.g. Cinepak®, Intel Indeo®

Page 22: Lecture Two Compression & File Specification Standards.

22

Common audio file formats

• WAV sampled analogue sound• AIFF• AU• MIDI records keys / instruments / time• MP2 / MP3 audio track from MPEG• RA / RAM RealAudio streaming technology

Page 23: Lecture Two Compression & File Specification Standards.

23

The BMP file format

• Basic need to store pixel values - but what do they mean?

ColourLook-up

Table(CLUT)

Pixel Value RGB Value OutputDevice

Page 24: Lecture Two Compression & File Specification Standards.

24

Elements of the file specification

• Initial identifier: BM• Size of the file - allows for quick check• Offset through the header to the pixel data• Width & height of the bitmap, in pixels• Number of bits per pixel• Type of compression in use (if any)• Pixels / metre in ‘x’ and ‘y’ dimensions

Page 25: Lecture Two Compression & File Specification Standards.

25

More elements

• Number of colours in the CLUT• Number of important colours• CLUT + pixel data follows

Questions• Why is each element included?• Are there any limitations to a BMP?

Page 26: Lecture Two Compression & File Specification Standards.

26

Image & Video Coding Standards

• JPEG (Joint Photographic Experts Group)

• MPEG (Motion Picture Experts Group)– MPEG I used by the Video CD standard– MPEG II in wide use, digital TV broadcast and DVDs– MPEG IV for multimedia, MPEG VII for description– MPEG-21 for multimedia framework, started June '00

Page 27: Lecture Two Compression & File Specification Standards.

27

An MPEG Example

Page 28: Lecture Two Compression & File Specification Standards.

28

Video Coding - MPEG

• I-pictures (intra-coded picture)– used at the start and at cut frames

• P-pictures (predictive coded picture)– block(s) within the picture reference the previous

picture

• B-pictures (bi-directional predictive coded pictures)– require info from the previous and next pictures in order

to draw themselves

Page 29: Lecture Two Compression & File Specification Standards.

29

An MPEG Example

Page 30: Lecture Two Compression & File Specification Standards.

Video & Video Encoding

Page 31: Lecture Two Compression & File Specification Standards.

31

Video on Demand

• Theoretically requires huge bandwidth, but…• Start the same movie every x minutes (BSkyB)• Change the frame-rate to make movie fit slot

– airline favourite

• Can allow viewer to pause and resume viewing• Future trend for cable & satellite

Page 32: Lecture Two Compression & File Specification Standards.

32

What is video?

• Flick books are a sequence of still images• Cine-film is a sequence of still images (frames)

– objects are moved slightly between frames– when shown in rapid succession => movement

• Cine-film shot at 24 fps (frames per second)– projected at 48 fps to reduce flicker close to screen

• Video is a digital version of cine-film at ~25Hz

Page 33: Lecture Two Compression & File Specification Standards.

33

Frame Rate

• Number of images recorded per second• Easy to reduce frame rate for playback• Can ‘get away with’ 12 fps (poorer quality)

– depends on the speed of the action in the video

• Lower frame rates often used for video conferencing

• Trade off in the use of bandwidth

Page 34: Lecture Two Compression & File Specification Standards.

34

Bandwidth

• A measure of the capacity of a communications channel

• Typical values:– 56kbps (bits per second) for modern modem– 64kbps for single ISDN channel (128k for ISDN2)– 384kbps for 6 ISDN channels (video conferencing)– need ISDN30 to reach MegaStream link (c. 2Mbps)

Page 35: Lecture Two Compression & File Specification Standards.

35

Example 1

56kbps modem connection

25Hz frame rate => 56/25 = 2.24kb per frame

Assume 8-bit colour depth => 2.24/8 = 280 pels

Image size of about 20x14 pixels (useless!)

[ More typical is 192x144 pixels (8-bit depth)

at frame rate of 8 fps using compression

of ~30:1 to fit the bandwidth.]

Page 36: Lecture Two Compression & File Specification Standards.

36

Example 2

ISDN6 offers 384kbps. How might this be usedin video conferencing?

Full duplex => 384 / 2 = 192kbps each wayOPTION 1: 350x260 @ 8fps (30:1, 8-bit pels)OPTION 2: 192x144 @ 25fps (29:1, 8-bit pels)

Exercise: Assuming same conditions, what bandwidth would berequired to support full-screen conferencing at 25fps?

Page 37: Lecture Two Compression & File Specification Standards.

37

Example 3

An AVI file is 1.9MB in size. How long will it

take to download this over a 56kbps modem?

56kbps = 56,000 bits per second

1.9MB = 1.9 * 1024 * 1024 * 8 = 15,938,355 b

Time = 15938355 / 56000 = 285 s (4m 45s)

(Assumes perfect connection and full bandwidth.)

Page 38: Lecture Two Compression & File Specification Standards.

38

Video Encoding

• PAL - UK television standard– 768 x 576 resolution (much less in practice), 25fps

• NTSC - US television standard– 640 x 480 resolution (again, less when in use) 29fps

• SECAM – France and eastern europe, far east– 768 x 576 resolution (again, less when in use) 25fps

Page 39: Lecture Two Compression & File Specification Standards.

39

Frame grabber

• Card of electronics required for direct input of video into a computer system

• ‘Grabs’ an image of a set resolution at a set frame-rate, e.g. 192x144 at 15Hz

• Stores the image in digital form on hard disk• Compression or other encoding up to software• Match of framegrabber and camera required

Page 40: Lecture Two Compression & File Specification Standards.

40

Review

• Image compression techniques– Lossy and lossless– Run length encoding & Quadtree

• Common Image standards• MPEG• Video on demand